Skip to content

Commit

Permalink
feat: update apollo libs
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebergamin committed Aug 3, 2023
1 parent 59774b9 commit 42360e3
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 230 deletions.
2 changes: 1 addition & 1 deletion lib/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildSubgraphSchema } from '@apollo/federation';
import { buildSubgraphSchema } from '@apollo/subgraph';
import type { DocumentNode, GraphQLSchema } from 'graphql';
import { mapSchema } from '@graphql-tools/utils';
import type { SchemaMapper } from '@graphql-tools/utils';
Expand Down
50 changes: 34 additions & 16 deletions lib/utils/createNodeGatewayConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ const nodeServiceConfig = {
const servicesSupergraphSdl = `\
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
{
query: Query
}
directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
Expand Down Expand Up @@ -97,18 +101,22 @@ type User implements Node
const supergraphSdl = `\
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
{
query: Query
}
directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
Expand All @@ -122,7 +130,7 @@ type Book
scalar join__FieldSet
enum join__Graph {
NODESERVICE @join__graph(name: "NodeService", url: "node-url/717d11284d78325251f8f664cdd242ae1d970b2ce4be17c170cb8988de12392f")
NODESERVICE @join__graph(name: "NodeService", url: "node-url/3d1c5319f5a8c5cf005b8bdaf1fce8164ff6364efe185973d4b3c9156fa0843a")
BOOK @join__graph(name: "book", url: "http://localhost:4003/graphql")
POST @join__graph(name: "post", url: "http://localhost:4002/graphql")
USER @join__graph(name: "user", url: "http://localhost:4001/graphql")
Expand Down Expand Up @@ -274,18 +282,22 @@ describe('createNodeGatewayConfig', () => {
update(`\
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
{
query: Query
}
directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
Expand Down Expand Up @@ -335,6 +347,7 @@ type Query
type User implements Node
@join__implements(graph: USER, interface: "Node")
@join__type(graph: USER, key: "id")
@join__type(graph: POST, key: "id")
{
id: ID!
name: String!
Expand Down Expand Up @@ -368,25 +381,29 @@ type User implements Node
expect(sdlOptions.update).toBeCalledWith(`\
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
{
query: Query
}
directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
scalar join__FieldSet
enum join__Graph {
NODESERVICE @join__graph(name: "NodeService", url: "node-url/ea5888f40e01ad6953a46749a751c7f6b697309ba6e6b557b736a151ba1022ce")
NODESERVICE @join__graph(name: "NodeService", url: "node-url/30cd99f094471afd1a723ff4db537fae9acffcd06e5d41944db644398e970d12")
POST @join__graph(name: "post", url: "http://localhost:4002/graphql")
USER @join__graph(name: "user", url: "http://localhost:4001/graphql")
}
Expand Down Expand Up @@ -429,17 +446,18 @@ type Query
@join__type(graph: USER)
{
node(id: ID!): Node @join__field(graph: NODESERVICE)
user: User @join__field(graph: USER)
user: User @join__field(graph: POST) @join__field(graph: USER)
}
type User implements Node
@join__implements(graph: NODESERVICE, interface: "Node")
@join__implements(graph: USER, interface: "Node")
@join__type(graph: NODESERVICE, key: "id")
@join__type(graph: POST, key: "id")
@join__type(graph: USER, key: "id")
{
id: ID!
name: String! @join__field(graph: USER)
name: String! @join__field(graph: POST) @join__field(graph: USER)
}`);

cleanup?.();
Expand Down
7 changes: 2 additions & 5 deletions lib/utils/createNodeSupergraphSdlHookAndDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import type {
SupergraphManager,
SupergraphSdlHook,
} from '@apollo/gateway';
import {
buildSchema,
extractSubgraphsFromSupergraph,
} from '@apollo/federation-internals';
import { Supergraph } from '@apollo/federation-internals';
import type { Subgraphs } from '@apollo/federation-internals';
import { compose } from '@apollo/composition';
import { createHash } from '@apollo/utils.createhash';
Expand All @@ -26,7 +23,7 @@ const emptyContext = {} as unknown as NodeSupergraphContext;
// NOTE: unfortunately we can't get the parsed Subgraphs from IntrospectAndCompose,
// then we need to parse, rebuild the schema and extract subgraphs from it
const buildSubgraphsFromSdl = (sdl: string): Subgraphs =>
extractSubgraphsFromSupergraph(buildSchema(sdl, { validate: false }));
Supergraph.build(sdl, { validateSupergraph: false }).subgraphs();

// NOTE: the following code is similar to IntrospectAndCompose.createSupergraphFromSubgraphList(),
// adapted to receive Subgraphs + compose instead of ServiceDefinition[] + composeServices
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
"yarn": "^1.21.1"
},
"dependencies": {
"@apollo/federation-internals": "^2.0.4",
"@apollo/federation-internals": "^2.5.1",
"@apollo/utils.createhash": "^1.1.0",
"@graphql-tools/utils": "^8.6.12",
"graphql-tag": "^2.12.6",
"lodash.difference": "^4.5.0",
"yargs": "^17.5.1"
"yargs": "^17.5.1",
"@apollo/composition": "^2.5.1",
"@apollo/gateway": "^2.5.1",
"@apollo/subgraph": "^2.5.1"
},
"peerDependencies": {
"@apollo/composition": "^2.0.4",
"@apollo/federation": "^0.36.1",
"@apollo/gateway": "^2.0.4",
"@apollo/composition": "^2.5.1",
"@apollo/gateway": "^2.5.1",
"@apollo/subgraph": "^2.5.1",
"graphql": "^16.5.0"
},
"devDependencies": {
"@apollo/composition": "^2.0.4",
"@apollo/federation": "^0.36.1",
"@apollo/gateway": "^2.0.4",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-angular": "^17.0.0",
"@types/jest": "^28.1.0",
Expand Down
4 changes: 2 additions & 2 deletions test/services.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApolloServer, gql } from 'apollo-server';
import { DocumentNode } from 'graphql';
import { buildSubgraphSchema } from '@apollo/federation';
import { buildSubgraphSchema } from '@apollo/subgraph';
import { GraphQLResolverMap } from 'apollo-graphql';

import { nodeInterface, createNodeResolver } from '../lib';
Expand Down Expand Up @@ -99,7 +99,7 @@ const createService = async <T>(
): Promise<ServiceDescription> => {
const server = new ApolloServer({
schema: buildSubgraphSchema({
resolvers,
resolvers: resolvers as GraphQLResolverMap<unknown>,
typeDefs,
}),
});
Expand Down
Loading

0 comments on commit 42360e3

Please sign in to comment.