From 17d4ad38831bd58d5142b9be524839496643258f Mon Sep 17 00:00:00 2001 From: Matt Farmer Date: Sat, 25 Apr 2020 10:10:09 -0700 Subject: [PATCH] Add option to not include `specifiedByUrl` in introspection query --- src/type/__tests__/introspection-test.js | 1 + src/utilities/__tests__/buildClientSchema-test.js | 5 ++++- .../__tests__/getIntrospectionQuery-test.js | 12 ++++++++++++ src/utilities/getIntrospectionQuery.d.ts | 4 ++++ src/utilities/getIntrospectionQuery.js | 10 +++++++++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/type/__tests__/introspection-test.js b/src/type/__tests__/introspection-test.js index e2ed1092a1..26148f4ae3 100644 --- a/src/type/__tests__/introspection-test.js +++ b/src/type/__tests__/introspection-test.js @@ -31,6 +31,7 @@ describe('Introspection', () => { const source = getIntrospectionQuery({ descriptions: false, directiveIsRepeatable: true, + specifiedByUrl: true, }); const result = graphqlSync({ schema, source }); diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index 2c539e7189..7398413289 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -33,7 +33,10 @@ import { introspectionFromSchema } from '../introspectionFromSchema'; * returns that schema printed as SDL. */ function cycleIntrospection(sdlString: string): string { - const options = { directiveIsRepeatable: true }; + const options = { + directiveIsRepeatable: true, + specifiedByUrl: true, + }; const serverSchema = buildSchema(sdlString); const initialIntrospection = introspectionFromSchema(serverSchema, options); diff --git a/src/utilities/__tests__/getIntrospectionQuery-test.js b/src/utilities/__tests__/getIntrospectionQuery-test.js index e25a906e19..462d683acf 100644 --- a/src/utilities/__tests__/getIntrospectionQuery-test.js +++ b/src/utilities/__tests__/getIntrospectionQuery-test.js @@ -51,4 +51,16 @@ describe('getIntrospectionQuery', () => { getIntrospectionQuery({ descriptions: false, schemaDescription: true }), ).to.not.match(/\bdescription\b/); }); + + it('include "specifiedByUrl" field', () => { + expect(getIntrospectionQuery()).to.not.match(/\bspecifiedByUrl\b/); + + expect(getIntrospectionQuery({ specifiedByUrl: true })).to.match( + /\bspecifiedByUrl\b/, + ); + + expect(getIntrospectionQuery({ specifiedByUrl: false })).to.not.match( + /\bspecifiedByUrl\b/, + ); + }); }); diff --git a/src/utilities/getIntrospectionQuery.d.ts b/src/utilities/getIntrospectionQuery.d.ts index da0fdcd186..b1d5ecc174 100644 --- a/src/utilities/getIntrospectionQuery.d.ts +++ b/src/utilities/getIntrospectionQuery.d.ts @@ -6,6 +6,10 @@ export interface IntrospectionOptions { // Default: true descriptions: boolean; + // Whether to include `specifiedByUrl` in the introspection result. + // Default: false + specifiedByUrl?: boolean; + // Whether to include `isRepeatable` flag on directives. // Default: false directiveIsRepeatable?: boolean; diff --git a/src/utilities/getIntrospectionQuery.js b/src/utilities/getIntrospectionQuery.js index 045faab732..51e94cd9a1 100644 --- a/src/utilities/getIntrospectionQuery.js +++ b/src/utilities/getIntrospectionQuery.js @@ -7,6 +7,10 @@ export type IntrospectionOptions = {| // Default: true descriptions?: boolean, + // Whether to include `specifiedByUrl` in the introspection result. + // Default: false + specifiedByUrl?: boolean, + // Whether to include `isRepeatable` field on directives. // Default: false directiveIsRepeatable?: boolean, @@ -19,12 +23,16 @@ export type IntrospectionOptions = {| export function getIntrospectionQuery(options?: IntrospectionOptions): string { const optionsWithDefault = { descriptions: true, + specifiedByUrl: false, directiveIsRepeatable: false, schemaDescription: false, ...options, }; const descriptions = optionsWithDefault.descriptions ? 'description' : ''; + const specifiedByUrl = optionsWithDefault.specifiedByUrl + ? 'specifiedByUrl' + : ''; const directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable ? 'isRepeatable' : ''; @@ -58,7 +66,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string { kind name ${descriptions} - specifiedByUrl + ${specifiedByUrl} fields(includeDeprecated: true) { name ${descriptions}