dotansimha/graphql-code-generator

source option

Open

#6363 aperta il 25 lug 2021

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)TypeScript (1295 fork)batch import
corehelp wantedkind/enhancement

Metriche repository

Star
 (10.341 star)
Metriche merge PR
 (Merge medio 22g 9h) (53 PR mergiate in 30 g)

Descrizione

Is your feature request related to a problem? Please describe.

When testing it's useful to get an operation's source

import { NoParamQuery } from '../codegen/schema';

describe('with NoParamQuery script child', function() {
  let element;
  beforeEach(async function() {
    element = await getElement();
    element.innerHTML = `<script type="application/graphql">${NoParamQuery.loc!.source.body}</script>`;
    await nextFrame();
  });

  it('sets query property', function() {
    expect(element?.query).to.deep.equal(gql(NoParamQuery.loc!.source.body));
  });
});

Describe the solution you'd like .graphqlrc.yml

extensions:
  codegen:
    config:
      dedupeOperationSuffix: true
      namingConvention: keep
      documentVariableSuffix: ''
      source: true

    generates:
      test/schema.ts:
        schema: test/graphql/test.schema.graphql
        plugins:
          - typescript
          - typescript-operations
          - typed-document-node

        documents:
          - test/graphql/*.query.graphql
          - test/graphql/*.mutation.graphql
          - test/graphql/*.subscription.graphql
          - test/graphql/*.fragment.graphql

Describe alternatives you've considered build-time transformers like rollup-plugin-graphql etc.

Additional context source could be boolean|string[] to provide users with an allowlist of operations to include sources for, if they need source at runtime for some reason but want to lower bundle sizes.

source:
  - NoParamQuery
  - SourcyMutation

Guida contributor