Right 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
Right now to generate operations we must explicitly write
*.graphqlorgqltag 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:
We can easily write the
computeSelectionfunction, also with typescript nested typing: https://stackoverflow.com/a/54949737