Skip to content

Commit

Permalink
Ensure UrlLoader uses introspection options
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrearden committed Jul 30, 2020
1 parent 0516f95 commit 1437736
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
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
12 changes: 12 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,18 @@ type CustomQuery {
expect(headers.c).toContain(`3`);
});

it('Should utilize extra introspection options', async () => {
const description = 'Schema description'
const testSchema = makeExecutableSchema({ typeDefs: `"${description}"` + testTypeDefs });
const server = mockGraphQLServer({schema: testSchema, host: testHost, path: testPath});
const source = await loader.load(testUrl, { schemaDescription: true });

server.done();

expect(source).toBeDefined();
expect(source.schema.description).toBe(description);
});

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

0 comments on commit 1437736

Please sign in to comment.