Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to treat a subgraph as regular graphql api #496

Merged
merged 5 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -44,7 +44,7 @@ require (
github.com/tidwall/gjson v1.11.0
github.com/tidwall/sjson v1.1.5
github.com/valyala/fasthttp v1.26.0
github.com/wundergraph/graphql-go-tools v1.60.3
github.com/wundergraph/graphql-go-tools v1.60.4
go.uber.org/zap v1.18.1
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -527,8 +527,8 @@ github.com/vmihailenco/msgpack/v5 v5.1.0 h1:+od5YbEXxW95SPlW6beocmt8nOtlh83zqat5
github.com/vmihailenco/msgpack/v5 v5.1.0/go.mod h1:C5gboKD0TJPqWDTVTtrQNfRbiBwHZGo8UTqP/9/XvLI=
github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc=
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/wundergraph/graphql-go-tools v1.60.3 h1:HNKjKJ80MhEHx6ODeTogU/sS2ukMzkZPA2b4gF9PlVg=
github.com/wundergraph/graphql-go-tools v1.60.3/go.mod h1:kHPC4B6vQFMohnEofRgcy37eYhoDsjzxJ4P8ZhQrV4M=
github.com/wundergraph/graphql-go-tools v1.60.4 h1:7whFhINu4x6oFNMvDj5tx1HHAbtIS2U0t4w6blXgWYo=
github.com/wundergraph/graphql-go-tools v1.60.4/go.mod h1:kHPC4B6vQFMohnEofRgcy37eYhoDsjzxJ4P8ZhQrV4M=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
Expand Down
12 changes: 0 additions & 12 deletions packages/sdk/src/definition/federation-introspection.ts
Expand Up @@ -11,18 +11,6 @@ import { HeadersBuilder, mapHeaders } from './headers-builder';
import { Fetcher } from './introspection-fetcher';
import { Logger } from '../logger';

export const isFederationService = (schema: GraphQLSchema): boolean => {
const queryType = schema.getQueryType();
if (queryType === undefined || queryType === null) {
return false;
}
const fields = queryType.getFields();
if (fields === undefined) {
return false;
}
return Object.keys(fields).indexOf('_service') !== -1;
};

export const fetchFederationServiceSDL = async (
url: string,
headers?: Record<string, string>,
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/src/definition/graphql-introspection.ts
@@ -1,4 +1,4 @@
import { fetchFederationServiceSDL, isFederationService } from './federation-introspection';
import { fetchFederationServiceSDL } from './federation-introspection';
import { configuration } from '../graphql/configuration';
import {
buildClientSchema,
Expand Down Expand Up @@ -69,7 +69,9 @@ export const resolveGraphqlIntrospectionHeaders = (headers?: { [key: string]: HT
return baseHeaders;
};

export const introspectGraphql = async (introspection: GraphQLIntrospection): Promise<GraphQLApi> => {
export const introspectGraphql = async (
introspection: Omit<GraphQLIntrospection, 'isFederation'>
): Promise<GraphQLApi> => {
return introspectWithCache(introspection, async (introspection: GraphQLIntrospection): Promise<GraphQLApi> => {
const headersBuilder = new HeadersBuilder();
const introspectionHeadersBuilder = new HeadersBuilder();
Expand All @@ -87,7 +89,7 @@ export const introspectGraphql = async (introspection: GraphQLIntrospection): Pr

let schema = await introspectGraphQLSchema(introspection, introspectionHeaders);
schema = lexicographicSortSchema(schema);
const federationEnabled = isFederationService(schema);
const federationEnabled = introspection.isFederation || false;
const upstreamSchema = cleanupSchema(schema, introspection);
const { schemaSDL, customScalarTypeFields } = transformSchema.replaceCustomScalars(upstreamSchema, introspection);
let serviceSDL: string | undefined;
Expand Down