dotansimha / dotansimha/graphql-code-generator

Support for wildcard comment

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

Description

I would like to be able to quickly select all fields on a type. This feature has been [discussed at length](https://github.com/graphql/graphql-spec/issues/127) as an addition to the GraphQL spec, but I think it makes more sense at the code generator level.

## Why is this needed?
My personal use case is simply building a static website on top of NextJS and GraphCMS. However I find myself constantly forgetting to add fields to my queries, and just repeating the work I've done in the CMS. A wildcard syntax would greatly alleviate these problems.

## Proposal
I would suggest two different magic comments, similar to the `import` syntax.

```graphql
aField {
__typename # placeholder field to silence syntax error
# ...all
}

anotherField {
__typename
# ...allScalars
}
```

The first form queries all fields recursively, while the second form limits itself to scalar types.

## Alternatives
[GenQL](https://genql.now.sh) currently supports this via a special `everything` object, however I find JS query builders rather ugly to work with.

## Implementation
I am not a contributor to this project and haven't worked on the backend side of GraphQL, so I'm not sure exactly what the implementation would look like. I wonder if it would be possible to build on top of the introspection plugin.

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.