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

Introduce GraphQL Importer #232

Open
ostridm opened this issue Mar 25, 2024 · 0 comments · May be fixed by #233
Open

Introduce GraphQL Importer #232

ostridm opened this issue Mar 25, 2024 · 0 comments · May be fixed by #233
Assignees
Labels
Type: enhancement New feature or request.

Comments

@ostridm
Copy link
Contributor

ostridm commented Mar 25, 2024

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

@ostridm ostridm added the Type: enhancement New feature or request. label Mar 25, 2024
@ostridm ostridm self-assigned this Mar 25, 2024
ostridm added a commit that referenced this issue Mar 25, 2024
@ostridm ostridm linked a pull request Mar 25, 2024 that will close this issue
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant