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

Ensure UrlLoader uses introspection options #1854

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 packages/loaders/url/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
async getSubschemaConfig(pointer: SchemaPointerSingle, options: LoadFromUrlOptions) {
const { executor, subscriber } = await this.getExecutorAndSubscriber(pointer, options);
return {
schema: await introspectSchema(executor),
schema: await introspectSchema(executor, undefined, options as IntrospectionOptions),
executor,
subscriber,
};
Expand Down
10 changes: 10 additions & 0 deletions packages/loaders/url/tests/url-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ type CustomQuery {
expect(headers.c).toContain(`3`);
});

it('Should utilize extra introspection options', async () => {
const server = mockGraphQLServer({schema: testSchema, host: testHost, path: testPath});
const source = await loader.load(testUrl, { descriptions: false });

server.done();

expect(source).toBeDefined();
expect(source.schema.getQueryType().description).toBeUndefined();
});

it('Absolute file path should not be accepted as URL', async () => {
expect(await loader.canLoad(cwd(), {})).toBeFalsy();
});
Expand Down
17 changes: 13 additions & 4 deletions packages/wrap/src/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getIntrospectionQuery,
buildClientSchema,
parse,
IntrospectionOptions,
IntrospectionQuery,
} from 'graphql';

Expand All @@ -26,17 +27,25 @@ function getSchemaFromIntrospection(introspectionResult: ExecutionResult<Introsp
}
}

export async function introspectSchema(executor: AsyncExecutor, context?: Record<string, any>): Promise<GraphQLSchema> {
const parsedIntrospectionQuery: DocumentNode = parse(getIntrospectionQuery());
export async function introspectSchema(
executor: AsyncExecutor,
context?: Record<string, any>,
options?: IntrospectionOptions
): Promise<GraphQLSchema> {
const parsedIntrospectionQuery: DocumentNode = parse(getIntrospectionQuery(options));
const introspectionResult = await executor<IntrospectionQuery>({
document: parsedIntrospectionQuery,
context,
});
return getSchemaFromIntrospection(introspectionResult);
}

export function introspectSchemaSync(executor: SyncExecutor, context?: Record<string, any>): GraphQLSchema {
const parsedIntrospectionQuery: DocumentNode = parse(getIntrospectionQuery());
export function introspectSchemaSync(
executor: SyncExecutor,
context?: Record<string, any>,
options?: IntrospectionOptions
): GraphQLSchema {
const parsedIntrospectionQuery: DocumentNode = parse(getIntrospectionQuery(options));
const introspectionResult = executor<IntrospectionQuery>({
document: parsedIntrospectionQuery,
context,
Expand Down