diff --git a/.gitignore b/.gitignore index 1ac43d6..004c162 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,7 @@ node_modules/ # Intellij Configuration Files .idea/ -generated-schema.graphql \ No newline at end of file +generated-schema.graphql + +undefined.json +target.list \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c117bd8..72acf2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,9 @@ "hasInstallScript": true, "license": "MIT", "dependencies": { - "@apollo/server": "^4.0.0", - "@apollo/server-plugin-response-cache": "^4.1.2", - "@apollo/subgraph": "^2.5.0", + "@apollo/server": "^4.10.2", + "@apollo/server-plugin-response-cache": "^4.1.3", + "@apollo/subgraph": "^2.7.2", "graphql": "latest", "graphql-tag": "latest", "lodash": "^4.17.21", @@ -62,17 +62,17 @@ } }, "node_modules/@apollo/cache-control-types": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.2.tgz", - "integrity": "sha512-Por80co1eUm4ATsvjCOoS/tIR8PHxqVjsA6z76I6Vw0rFn4cgyVElQcmQDIZiYsy41k8e5xkrMRECkM2WR8pNw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.3.tgz", + "integrity": "sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g==", "peerDependencies": { "graphql": "14.x || 15.x || 16.x" } }, "node_modules/@apollo/federation-internals": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@apollo/federation-internals/-/federation-internals-2.5.0.tgz", - "integrity": "sha512-xpgcM5WXiFarsMbcjenAqToqcWXpnNHeGq0vT8qQ4OcAq9BdwMYwVNjmPfatlBpjCdcNQFfWBQJsiQZTulYFww==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/@apollo/federation-internals/-/federation-internals-2.7.2.tgz", + "integrity": "sha512-i+9mbw8UN6P+i5xpLxH3m8n3zqEBzoN8a1cct4yrab9loiZeIlxW8cLXzqglEMic++Sz9tai4L21ZY0GlW8ebg==", "dependencies": { "@types/uuid": "^9.0.0", "chalk": "^4.1.0", @@ -111,19 +111,19 @@ } }, "node_modules/@apollo/server": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/@apollo/server/-/server-4.6.0.tgz", - "integrity": "sha512-02dgZ5ywBZP7xVZ+Xf62uEtA0jCYcpD5gEluCADudUSwbGuQTnJ9F056SxOVLpJRM69sWDrOMKF5kncYYH5wSA==", + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/@apollo/server/-/server-4.10.2.tgz", + "integrity": "sha512-qlTZE4XyzMPprtkxFjmPxMwc2KC4nvNQrKXk2PMotEACKcaLXVZFIgstxbSqBCNl2KgzbsgU1g6vvbV6Xcfikw==", "dependencies": { - "@apollo/cache-control-types": "^1.0.2", - "@apollo/server-gateway-interface": "^1.1.0", - "@apollo/usage-reporting-protobuf": "^4.1.0", + "@apollo/cache-control-types": "^1.0.3", + "@apollo/server-gateway-interface": "^1.1.1", + "@apollo/usage-reporting-protobuf": "^4.1.1", "@apollo/utils.createhash": "^2.0.0", "@apollo/utils.fetcher": "^2.0.0", "@apollo/utils.isnodelike": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0", "@apollo/utils.logger": "^2.0.0", - "@apollo/utils.usagereporting": "^2.0.0", + "@apollo/utils.usagereporting": "^2.1.0", "@apollo/utils.withrequired": "^2.0.0", "@graphql-tools/schema": "^9.0.0", "@josephg/resolvable": "^1.0.0", @@ -131,7 +131,6 @@ "@types/express-serve-static-core": "^4.17.30", "@types/node-fetch": "^2.6.1", "async-retry": "^1.2.1", - "body-parser": "^1.20.0", "cors": "^2.8.5", "express": "^4.17.1", "loglevel": "^1.6.8", @@ -150,11 +149,11 @@ } }, "node_modules/@apollo/server-gateway-interface": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-1.1.0.tgz", - "integrity": "sha512-0rhG++QtGfr4YhhIHgxZ9BdMFthaPY6LbhI9Au90osbfLMiZ7f8dmZsEX1mp7O1h8MJwCu6Dp0I/KcGbSvfUGA==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-1.1.1.tgz", + "integrity": "sha512-pGwCl/po6+rxRmDMFgozKQo2pbsSwE91TpsDBAOgf74CRDPXHHtM88wbwjab0wMMZh95QfR45GGyDIdhY24bkQ==", "dependencies": { - "@apollo/usage-reporting-protobuf": "^4.0.0", + "@apollo/usage-reporting-protobuf": "^4.1.1", "@apollo/utils.fetcher": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0", "@apollo/utils.logger": "^2.0.0" @@ -164,9 +163,9 @@ } }, "node_modules/@apollo/server-plugin-response-cache": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@apollo/server-plugin-response-cache/-/server-plugin-response-cache-4.1.2.tgz", - "integrity": "sha512-HlKe5s/gjvHAebh4LKCfQNBEJod/W+bsEd7wAyc6DyV9I8MquMX6mV42bkU2m+AUdNIltOlLRqnBEKJezG342Q==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@apollo/server-plugin-response-cache/-/server-plugin-response-cache-4.1.3.tgz", + "integrity": "sha512-8WaP4Xo9GGIbWn4ZG/TlYKZLo/YI8tuORvxzLOKnZa3EqUvt7iTCGHX491dWNiGkm93VgDDdo5r0WEvLDdHSmQ==", "dependencies": { "@apollo/utils.createhash": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0" @@ -180,12 +179,12 @@ } }, "node_modules/@apollo/subgraph": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-2.5.0.tgz", - "integrity": "sha512-7Wj5RwHiQk9xAETX7k2LzlkiKBAiEqNGymPTq+7pXdDtfEX+FooqTGuyon7e4cgkgZ9uO5Mb1kRaHGTsqndaBg==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-2.7.2.tgz", + "integrity": "sha512-n3N8HULcj0Mpegsgd9z4MK2oEbC4BVJFuhcrliNdpq+vlcmvOaEaHGMw+ZgBi6aiZjhKb/2nsmQzzr8G2RXOLw==", "dependencies": { "@apollo/cache-control-types": "^1.0.2", - "@apollo/federation-internals": "2.5.0" + "@apollo/federation-internals": "2.7.2" }, "engines": { "node": ">=14.15.0" @@ -195,9 +194,9 @@ } }, "node_modules/@apollo/usage-reporting-protobuf": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@apollo/usage-reporting-protobuf/-/usage-reporting-protobuf-4.1.0.tgz", - "integrity": "sha512-hXouMuw5pQVkzi8dgMybmr6Y11+eRmMQVoB5TF0HyTwAg9SOq/v3OCuiYqcVUKdBcskU9Msp+XvjAk0GKpWCwQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@apollo/usage-reporting-protobuf/-/usage-reporting-protobuf-4.1.1.tgz", + "integrity": "sha512-u40dIUePHaSKVshcedO7Wp+mPiZsaU6xjv9J+VyxpoU/zL6Jle+9zWeG98tr/+SZ0nZ4OXhrbb8SNr0rAPpIDA==", "dependencies": { "@apollo/protobufjs": "1.2.7" } @@ -309,11 +308,11 @@ } }, "node_modules/@apollo/utils.usagereporting": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@apollo/utils.usagereporting/-/utils.usagereporting-2.0.1.tgz", - "integrity": "sha512-18smkNfiSfu5yj2mpCIfSzmpDNh90a4PQ6t8kSwGKcPRD3KD83TfK7fF37fSRdnvO93dBkGreWisLXnCpqfWXg==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@apollo/utils.usagereporting/-/utils.usagereporting-2.1.0.tgz", + "integrity": "sha512-LPSlBrn+S17oBy5eWkrRSGb98sWmnEzo3DPTZgp8IQc8sJe0prDgDuppGq4NeQlpoqEHz0hQeYHAOA0Z3aQsxQ==", "dependencies": { - "@apollo/usage-reporting-protobuf": "^4.0.0", + "@apollo/usage-reporting-protobuf": "^4.1.0", "@apollo/utils.dropunuseddefinitions": "^2.0.1", "@apollo/utils.printwithreducedwhitespace": "^2.0.1", "@apollo/utils.removealiases": "2.0.1", @@ -2720,9 +2719,9 @@ "dev": true }, "node_modules/@types/uuid": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.2.tgz", - "integrity": "sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==" + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==" }, "node_modules/@types/ws": { "version": "8.5.3", @@ -8451,15 +8450,15 @@ } }, "@apollo/cache-control-types": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.2.tgz", - "integrity": "sha512-Por80co1eUm4ATsvjCOoS/tIR8PHxqVjsA6z76I6Vw0rFn4cgyVElQcmQDIZiYsy41k8e5xkrMRECkM2WR8pNw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.3.tgz", + "integrity": "sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g==", "requires": {} }, "@apollo/federation-internals": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@apollo/federation-internals/-/federation-internals-2.5.0.tgz", - "integrity": "sha512-xpgcM5WXiFarsMbcjenAqToqcWXpnNHeGq0vT8qQ4OcAq9BdwMYwVNjmPfatlBpjCdcNQFfWBQJsiQZTulYFww==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/@apollo/federation-internals/-/federation-internals-2.7.2.tgz", + "integrity": "sha512-i+9mbw8UN6P+i5xpLxH3m8n3zqEBzoN8a1cct4yrab9loiZeIlxW8cLXzqglEMic++Sz9tai4L21ZY0GlW8ebg==", "requires": { "@types/uuid": "^9.0.0", "chalk": "^4.1.0", @@ -8487,19 +8486,19 @@ } }, "@apollo/server": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/@apollo/server/-/server-4.6.0.tgz", - "integrity": "sha512-02dgZ5ywBZP7xVZ+Xf62uEtA0jCYcpD5gEluCADudUSwbGuQTnJ9F056SxOVLpJRM69sWDrOMKF5kncYYH5wSA==", + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/@apollo/server/-/server-4.10.2.tgz", + "integrity": "sha512-qlTZE4XyzMPprtkxFjmPxMwc2KC4nvNQrKXk2PMotEACKcaLXVZFIgstxbSqBCNl2KgzbsgU1g6vvbV6Xcfikw==", "requires": { - "@apollo/cache-control-types": "^1.0.2", - "@apollo/server-gateway-interface": "^1.1.0", - "@apollo/usage-reporting-protobuf": "^4.1.0", + "@apollo/cache-control-types": "^1.0.3", + "@apollo/server-gateway-interface": "^1.1.1", + "@apollo/usage-reporting-protobuf": "^4.1.1", "@apollo/utils.createhash": "^2.0.0", "@apollo/utils.fetcher": "^2.0.0", "@apollo/utils.isnodelike": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0", "@apollo/utils.logger": "^2.0.0", - "@apollo/utils.usagereporting": "^2.0.0", + "@apollo/utils.usagereporting": "^2.1.0", "@apollo/utils.withrequired": "^2.0.0", "@graphql-tools/schema": "^9.0.0", "@josephg/resolvable": "^1.0.0", @@ -8507,7 +8506,6 @@ "@types/express-serve-static-core": "^4.17.30", "@types/node-fetch": "^2.6.1", "async-retry": "^1.2.1", - "body-parser": "^1.20.0", "cors": "^2.8.5", "express": "^4.17.1", "loglevel": "^1.6.8", @@ -8520,38 +8518,38 @@ } }, "@apollo/server-gateway-interface": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-1.1.0.tgz", - "integrity": "sha512-0rhG++QtGfr4YhhIHgxZ9BdMFthaPY6LbhI9Au90osbfLMiZ7f8dmZsEX1mp7O1h8MJwCu6Dp0I/KcGbSvfUGA==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-1.1.1.tgz", + "integrity": "sha512-pGwCl/po6+rxRmDMFgozKQo2pbsSwE91TpsDBAOgf74CRDPXHHtM88wbwjab0wMMZh95QfR45GGyDIdhY24bkQ==", "requires": { - "@apollo/usage-reporting-protobuf": "^4.0.0", + "@apollo/usage-reporting-protobuf": "^4.1.1", "@apollo/utils.fetcher": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0", "@apollo/utils.logger": "^2.0.0" } }, "@apollo/server-plugin-response-cache": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@apollo/server-plugin-response-cache/-/server-plugin-response-cache-4.1.2.tgz", - "integrity": "sha512-HlKe5s/gjvHAebh4LKCfQNBEJod/W+bsEd7wAyc6DyV9I8MquMX6mV42bkU2m+AUdNIltOlLRqnBEKJezG342Q==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@apollo/server-plugin-response-cache/-/server-plugin-response-cache-4.1.3.tgz", + "integrity": "sha512-8WaP4Xo9GGIbWn4ZG/TlYKZLo/YI8tuORvxzLOKnZa3EqUvt7iTCGHX491dWNiGkm93VgDDdo5r0WEvLDdHSmQ==", "requires": { "@apollo/utils.createhash": "^2.0.0", "@apollo/utils.keyvaluecache": "^2.1.0" } }, "@apollo/subgraph": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-2.5.0.tgz", - "integrity": "sha512-7Wj5RwHiQk9xAETX7k2LzlkiKBAiEqNGymPTq+7pXdDtfEX+FooqTGuyon7e4cgkgZ9uO5Mb1kRaHGTsqndaBg==", + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/@apollo/subgraph/-/subgraph-2.7.2.tgz", + "integrity": "sha512-n3N8HULcj0Mpegsgd9z4MK2oEbC4BVJFuhcrliNdpq+vlcmvOaEaHGMw+ZgBi6aiZjhKb/2nsmQzzr8G2RXOLw==", "requires": { "@apollo/cache-control-types": "^1.0.2", - "@apollo/federation-internals": "2.5.0" + "@apollo/federation-internals": "2.7.2" } }, "@apollo/usage-reporting-protobuf": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@apollo/usage-reporting-protobuf/-/usage-reporting-protobuf-4.1.0.tgz", - "integrity": "sha512-hXouMuw5pQVkzi8dgMybmr6Y11+eRmMQVoB5TF0HyTwAg9SOq/v3OCuiYqcVUKdBcskU9Msp+XvjAk0GKpWCwQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@apollo/usage-reporting-protobuf/-/usage-reporting-protobuf-4.1.1.tgz", + "integrity": "sha512-u40dIUePHaSKVshcedO7Wp+mPiZsaU6xjv9J+VyxpoU/zL6Jle+9zWeG98tr/+SZ0nZ4OXhrbb8SNr0rAPpIDA==", "requires": { "@apollo/protobufjs": "1.2.7" } @@ -8622,11 +8620,11 @@ "requires": {} }, "@apollo/utils.usagereporting": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@apollo/utils.usagereporting/-/utils.usagereporting-2.0.1.tgz", - "integrity": "sha512-18smkNfiSfu5yj2mpCIfSzmpDNh90a4PQ6t8kSwGKcPRD3KD83TfK7fF37fSRdnvO93dBkGreWisLXnCpqfWXg==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@apollo/utils.usagereporting/-/utils.usagereporting-2.1.0.tgz", + "integrity": "sha512-LPSlBrn+S17oBy5eWkrRSGb98sWmnEzo3DPTZgp8IQc8sJe0prDgDuppGq4NeQlpoqEHz0hQeYHAOA0Z3aQsxQ==", "requires": { - "@apollo/usage-reporting-protobuf": "^4.0.0", + "@apollo/usage-reporting-protobuf": "^4.1.0", "@apollo/utils.dropunuseddefinitions": "^2.0.1", "@apollo/utils.printwithreducedwhitespace": "^2.0.1", "@apollo/utils.removealiases": "2.0.1", @@ -10530,9 +10528,9 @@ "dev": true }, "@types/uuid": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.2.tgz", - "integrity": "sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==" + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==" }, "@types/ws": { "version": "8.5.3", diff --git a/package.json b/package.json index b652692..cf63374 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "test": "jest" }, "dependencies": { - "@apollo/server": "^4.0.0", - "@apollo/server-plugin-response-cache": "^4.1.2", - "@apollo/subgraph": "^2.5.0", + "@apollo/server": "^4.10.2", + "@apollo/server-plugin-response-cache": "^4.1.3", + "@apollo/subgraph": "^2.7.2", "graphql": "latest", "graphql-tag": "latest", "lodash": "^4.17.21", diff --git a/src/__tests__/repo.test.ts b/src/__tests__/repo.test.ts index f91d550..567fd6a 100644 --- a/src/__tests__/repo.test.ts +++ b/src/__tests__/repo.test.ts @@ -1,40 +1,56 @@ -import { ApolloServer } from "@apollo/server"; +import { ApolloServer, ContextFunction } from "@apollo/server"; import { readFileSync } from "fs"; import gql from "graphql-tag"; import resolvers from "../resolvers"; +import { buildSubgraphSchema } from "@apollo/subgraph"; +import { + StandaloneServerContextFunctionArgument, +} from "@apollo/server/standalone"; +import { DataSourceContext } from "../types/DataSourceContext"; +import API from "../api"; + +const context: ContextFunction< + [StandaloneServerContextFunctionArgument], + DataSourceContext +> = async ({ req }) => ({ + api: new API(), +}); const server = new ApolloServer({ - typeDefs: gql( - readFileSync("schema.graphql", { - encoding: "utf-8", - }) - ), - resolvers, + schema: buildSubgraphSchema({ + typeDefs: gql( + readFileSync("schema.graphql", { + encoding: "utf-8", + }) + ), + resolvers, + }), }); describe("Repository Template Functionality", () => { it("Executes Location Entity Resolver", async () => { //Arrange - const query = `query ($representations: [_Any!]!) { - _entities(representations: $representations) { - ...on Thing { - name - } + const query = `query Capsules { + capsules { + id } }`; const variables = { representations: [{ __typename: "Thing", id: "1" }], }; - const expected = { - _entities: [{ name: "Name" }], + const expected = { + id: "5e9e2c5bf35918ed873b2664", }; //Act - const res = await server.executeOperation({ - query, - variables, - }); + const res = await server.executeOperation( + { + query, + variables, + }, + { contextValue: { api: new API() } } + ); //Assert expect(res.body.kind).toEqual("single"); - expect((res.body as any).singleResult.data).toEqual(expected); + expect((res.body as any).singleResult.data.capsules[0]).toEqual(expected); }); }); diff --git a/src/index.ts b/src/index.ts index 80af8f0..1403b68 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,12 @@ async function main() { introspection: true, plugins: [ ApolloServerPluginCacheControl({ defaultMaxAge: 86400 }), - responseCachePlugin(), + responseCachePlugin({ + shouldWriteToCache: async (requestContext) => { + console.log(JSON.stringify(requestContext)); + return false; + }, + }), { async serverWillStart() { return {