dotansimha / dotansimha/graphql-code-generator

source option

Open
#6,363 1 comment 0 reactions 0 assignees View on GitHub
core help wanted kind/enhancement
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

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

When testing it's useful to get an operation's source
```ts
import { NoParamQuery } from '../codegen/schema';

describe('with NoParamQuery script child', function() {
let element;
beforeEach(async function() {
element = await getElement();
element.innerHTML = `${NoParamQuery.loc!.source.body}`;
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`
```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.

```yml
source:
- NoParamQuery
- SourcyMutation
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.