Skip to content

Commit

Permalink
Namespace with apollo.subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Apr 20, 2022
1 parent e504e27 commit d4f7b7f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
18 changes: 12 additions & 6 deletions gateway-js/src/schema-helper/addResolversToSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export function addResolversToSchema(
if (fieldName === "__resolveReference") {
type.extensions = {
...type.extensions,
apolloSubgraph: {
...type.extensions.apolloSubgraph,
resolveReference: fieldConfig,
apollo: {
...type.extensions.apollo,
subgraph: {
...type.extensions.apollo?.subgraph,
resolveReference: fieldConfig,
}
},
};
} else if (fieldName.startsWith("__")) {
Expand Down Expand Up @@ -76,9 +79,12 @@ export function addResolversToSchema(
if (fieldName === "__resolveReference") {
type.extensions = {
...type.extensions,
apolloSubgraph: {
...type.extensions.apolloSubgraph,
resolveReference: fieldConfig
apollo: {
...type.extensions.apollo,
subgraph: {
...type.extensions.apollo?.subgraph,
resolveReference: fieldConfig,
}
},
};
} else if (fieldName.startsWith("__")) {
Expand Down
12 changes: 9 additions & 3 deletions gateway-js/src/typings/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ interface ApolloSubgraphExtensions<TContext> {

declare module 'graphql/type/definition' {
interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
}
}

interface GraphQLInterfaceTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
}
}

interface GraphQLUnionTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
}
}
}
18 changes: 12 additions & 6 deletions subgraph-js/src/schema-helper/buildSchemaFromSDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ export function addResolversToSchema(
if (fieldName === "__resolveReference") {
type.extensions = {
...type.extensions,
apolloSubgraph: {
...type.extensions.apolloSubgraph,
resolveReference: fieldConfig
apollo: {
...type.extensions.apollo,
subgraph: {
...type.extensions.apollo?.subgraph,
resolveReference: fieldConfig,
}
},
};
} else if (fieldName.startsWith("__")) {
Expand Down Expand Up @@ -165,9 +168,12 @@ export function addResolversToSchema(
if (fieldName === "__resolveReference") {
type.extensions = {
...type.extensions,
apolloSubgraph: {
...type.extensions.apolloSubgraph,
resolveReference: fieldConfig
apollo: {
...type.extensions.apollo,
subgraph: {
...type.extensions.apollo?.subgraph,
resolveReference: fieldConfig,
}
},
};
} else if (fieldName.startsWith("__")) {
Expand Down
12 changes: 9 additions & 3 deletions subgraph-js/src/schemaExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ interface ApolloSubgraphExtensions<TContext> {

declare module 'graphql/type/definition' {
interface GraphQLObjectTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
};
}

interface GraphQLInterfaceTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
};
}

interface GraphQLUnionTypeExtensions<_TSource = any, _TContext = any> {
apolloSubgraph?: ApolloSubgraphExtensions<_TContext>;
apollo?: {
subgraph?: ApolloSubgraphExtensions<_TContext>;
};
}
}
2 changes: 1 addition & 1 deletion subgraph-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function entitiesResolver({
}

const resolveReference =
type.extensions?.apolloSubgraph?.resolveReference ??
type.extensions.apollo?.subgraph?.resolveReference ??
function defaultResolveReference() {
return reference;
};
Expand Down

0 comments on commit d4f7b7f

Please sign in to comment.