Operations codegen without documents
See original GitHub issueRight now to generate operations we must explicitly write *.graphql or gql tag query/mutation documents, which are pretty verbose of all those documents.
I would like to discuss if we can have a plugin to generate operations without writing the documents:
- Because the operations are generated automatically, so they can contain only 1 query/mutation per operation. We need to manually write the document if we want combined query (like what we are doing right now):
// need to manually write combined operations
query combined($arg1: Arg1, $arg2: Arg2) {
b(arg1: $arg1) {
b1
b2
nested: {
nested_1
}
}
c(arg2: $arg2) {
c1
c2
}
}
- If the return type of that operation is a scalar without field selection -> perfect
- If the return type is object which needs field selection, we can generate the document dynamically like:
useBQuery({
variables: {
arg1: data,
},
}, {
// selected fields
b1: true,
b2: true,
nested: {
nested_1: true,
},
})
// which in the generated code it would dynamically generate the document as:
const doc = gql`
query b($arg1: Arg1) {
b(arg1: $arg1) {
${computeSelection(selectedFields)}
}
}
`
// then execute the query as usual...
We can easily write the computeSelection function, also with typescript nested typing: https://stackoverflow.com/a/54949737
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Ignoring documents if not present · Issue #4989 - GitHub
As of now, I am commenting out the documents statement in the codegen yaml file for every new service that I create and...
Read more >documents field - GraphQL Code Generator
The documents field should point to your GraphQL documents: query , mutation , subscription , and fragment . documents is only required if...
Read more >@graphql-codegen/operations-document - npm
GraphQL Code Generator plugin for generating GraphQL operation documents. Latest version: 1.0.0-alpha-17cc8e1de.0, last published: a year ago.
Read more >@graphql-codegen/operation-documents - npm package | Snyk
All security vulnerabilities belong to production dependencies of direct and indirect packages. License: MIT. Security Policy: No.
Read more >Swagger Codegen Documentation
The source code for the Swagger Codegen can be found in GitHub. ... If you're not using the latest master to generate API...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@ardatan Yes sorry you are correct, here is my updated:
typescript-operationsgenerate type defs for operations, but we need to fully generate type def of all fields in the return type recursively (look like this is already done)Okay, my fault. 😕 I was getting the following error:
Plugin "operations-document" requires extension to be '.graphql' !But this was due to the case that I used the extension
.tson the generated documents. I thought the error was related to the extension of the schema.