The project currently lacks of an ability to import a GraphQL schema from an existing introspection response (e.g. IntrospectionQuery) or single human-readable schema or even a collection of such schemas.
Proposed solution:
Since the GraphQL is not supposed to carry the URL information, we declare special envelope wrapping both an IntrospectionQuery or schema and URL.
To achieve this, the @har/sdk-core package utilized. Also, to be aligned with other API types re-exported from @har/sdk-core the graphql package types also are to be re-exported as follows:
export * from 'graphql';
import { IntrospectionQuery } from 'graphql';
export namespace GraphQL {
export interface GraphQLEnvelope<
T extends IntrospectionQuery | string | string[]
> {
url: string;
data: T;
}
}
We are introducing GraphQL.Document convenience type for further usage.
export namespace GraphQL {
export type Document = GraphQLEnvelope<IntrospectionQuery>;
}
Extend ImporterType enumeration
export enum ImporterType {
GRAPHQL = 'graphql'
}
Extend Doc conditional type deriving from ImporterType.GRAPHQL and GraphQL.Document
export type Doc<T extends DocType> =
...
: T extends ImporterType.GRAPHQL
? GraphQL.Document
...
Introduce a new Importer implementation
export class GraphQLImporter extends BaseImporter<ImporterType.GRAPHQL, GraphQL.Document>
Expected results:
GraphQLImporter able to handle GraphQL.Doument import as follows:
Given an IntrospectionQuery envelope
const document: GraphQL.Document = {
"url": "https://example.com/graphql",
"data": {
"__schema": {
"description": null,
"queryType": {
"name": "Query"
},
"mutationType": null,
"subscriptionType": null,
types: [...],
directives: [...],
}
}
};
const importer = new GraphQLImporter();
const imported = await importer.import(JSON.stringify(document));
Expect the imported contains the equivalent of document
Given a single SDL schema
const document: GraphQL.GraphQLEnvelope<string> = {
url: 'https://example.com/graphql',
data: 'type Foo { bar : String!} type Query { foo: Foo }'
};
const importer = new GraphQLImporter();
const imported = await importer.import(JSON.stringify(document));
Expect the imported contains the converted introspection which is an equivalent of schema given
Given a collection of SDL schema
const document: GraphQL.GraphQLEnvelope<string[]> = {
url: 'https://example.com/graphql',
data: ['type Foo { bar : String!}', 'type Query { foo: Foo }']
};
const importer = new GraphQLImporter();
const imported = await importer.import(JSON.stringify(document));
Expect the imported contains the converted introspection which is an equivalent of joined schema given
The project currently lacks of an ability to import a GraphQL schema from an existing introspection response (e.g.
IntrospectionQuery) or single human-readable schema or even a collection of such schemas.Proposed solution:
Since the GraphQL is not supposed to carry the URL information, we declare special envelope wrapping both an
IntrospectionQueryor schema and URL.To achieve this, the
@har/sdk-corepackage utilized. Also, to be aligned with other API types re-exported from @har/sdk-core thegraphqlpackage types also are to be re-exported as follows:We are introducing
GraphQL.Documentconvenience type for further usage.Extend
ImporterTypeenumerationExtend
Docconditional type deriving fromImporterType.GRAPHQLandGraphQL.DocumentIntroduce a new
ImporterimplementationExpected results:
GraphQLImporterable to handleGraphQL.Doumentimport as follows:Given an
IntrospectionQueryenvelopeExpect the
importedcontains the equivalent ofdocumentGiven a single SDL schema
Expect the
importedcontains the converted introspection which is an equivalent ofschemagivenGiven a collection of SDL schema
Expect the
importedcontains the converted introspection which is an equivalent of joinedschemagiven