[Plugin Request] Option to auto generate all queries/mutations/fragments from a schema #2349
-
For example I have a lot of mutations like this
And I don't what to white
for every mutation |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 7 replies
-
How would you know the correct selection set for each mutation? What if there was any recursion? |
Beta Was this translation helpful? Give feedback.
-
By default it could select everything except nested fields, if you need a different result you need to write a custom mutation. Also there could be a config option to include nested fields. Mutation with recursion could be skipped. |
Beta Was this translation helpful? Give feedback.
-
PRs are welcome :) Very similar to what AWS Amplify does. @n1ru4l we can add |
Beta Was this translation helpful? Give feedback.
-
I am trying to open a PR for this issue, but I am stuck at generating the https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/generate-and-save.ts#L27 |
Beta Was this translation helpful? Give feedback.
-
@Konosh93 The piece of code you mentioned is only the writing process of the output files, and not the generation itself. |
Beta Was this translation helpful? Give feedback.
-
I agree, and this is what I was trying to find a workaround for.
As you mentioned, the
I don't. Sorry, my wording was confusing. I want to make the generated documents files available for subsequent plugins.
|
Beta Was this translation helpful? Give feedback.
-
I see. It's not possible at the moment, because plugins are being executed after the point that all documents has been collected, parsed and validated against the schema. |
Beta Was this translation helpful? Give feedback.
-
Thanks. We figured that wouldn't be possible with the current interface. In our own use cases, we will be running the plugin before other plugins, using a separate config file. I will update this answer once the plugin is ready. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone. |
Beta Was this translation helpful? Give feedback.
-
At the moment, no updates on this issue. If someone really needs it, you can use PRs are welcome ;) |
Beta Was this translation helpful? Give feedback.
-
I tried to use graphql-mesh (graphql-toolkit is now merged in) but it does not generate graphql operations files. I would not use it to automatically integrate the files but you can easily copy paste modify everywhere you need graphql operations. Finally, big up to graphql-code-generator people ! |
Beta Was this translation helpful? Give feedback.
-
Hi !
That's great, I will have a try.
Best,
Le jeu. 20 mai 2021 à 19:48, Tam Nguyen ***@***.***> a écrit :
… Hey @Julien-Sytadelle <https://github.com/Julien-Sytadelle> , thanks a
lot for the note! With gqlg I was able to finally create a fully fledged
code generation system by combining 3 passes of graphql-codegen and one
pass of gqlg. The basic idea is to use graphql-codegen to generate the
combined ast, the model types, use gqlg to generate the fragments, and
then finish it off with one last graphql-codegen to combine it all
together.
This is the ultimate script I used, as well as the corresponding codegen
settings. I hope this helps someone else!
#!/bin/bash
yarn graphql-codegen -c ./graphql-codegen/codegen.ast.yml &&
yarn gqlg --schemaFilePath ./temp/all.graphql --destDirPath ./temp/gqlg/ &&
yarn graphql-codegen -c ./graphql-codegen/codegen.models.yml &&
yarn graphql-codegen -c ./graphql-codegen/codegen.hooks.yml &&
yarn eslint src/backend --fix # rounded off with a final lint, to match project settings
# codegen.ast.yml
schema:
- ../source-graphql/*.graphqloverwrite: truegenerates:
./temp/all.graphql:
plugins:
- schema-ast
# codegen.models.ymloverwrite: trueschema:
- ./temp/all.graphqlgenerates:
./temp/models.ts:
plugins:
- typescript
# codegen.hooks.ymloverwrite: trueschema:
- ./temp/all.graphqldocuments:
- ./temp/**/*.gql
- ./temp/models.tsgenerates:
./src/backend/app.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2349 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHW4EHKQSYBA722EQXGT5XLTOVDO3ANCNFSM4VYANNXQ>
.
--
Julien Cornaz
+33 6 84 33 50 65
Architecture de l'Information - R&D - .NET - Machine Learning
www.sytadelle.fr
|
Beta Was this translation helpful? Give feedback.
-
I had a similar problem and hacked something together with gqlg as well as an intermediate step, then wrapped it in a CLI application: I think it would be possible fully through graphql-codegen if it supported a
Another option is to write a plugin that uses graphql-codegen internally programatically. You could specify the plugins it should use. Not sure what the syntax should be:
|
Beta Was this translation helpful? Give feedback.
-
It looks like this PR (#6861) brings that feature! |
Beta Was this translation helpful? Give feedback.
-
I can make it with a custom document loader: codegen.yml: overwrite: true
schema: './**/*.graphql'
generates:
graphql.tsx:
documents:
- './**/*.graphql':
loader: './loader.js'
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-react-apollo'
config:
withHooks: true
withComponent: false
withHOC: false loader: const { parse } = require('graphql');
const { loadSchema } = require('@graphql-tools/load');
const { generateAll } = require('gql-generator-node');
const { GraphQLFileLoader } = require('@graphql-tools/graphql-file-loader');
module.exports = async (docString, config) => {
const schema5 = await loadSchema(docString, {
loaders: [new GraphQLFileLoader()],
});
const operations = generateAll(schema5);
let strigned = '';
for (const key in operations) {
if (Object.hasOwnProperty.call(operations, key)) {
const operation = operations[key];
for (const key in operation) {
if (Object.hasOwnProperty.call(operation, key)) {
const element = operation[key];
strigned += element;
}
}
}
}
const parsed = parse(strigned);
return parsed;
}; |
Beta Was this translation helpful? Give feedback.
At the moment, no updates on this issue.
If someone really needs it, you can use
buildOperationNodeForField
from@graphql-toolkit/common
(https://github.com/ardatan/graphql-toolkit/blob/master/packages/common/src/build-operation-for-field.ts). You can find an example for using it here: https://github.com/Urigo/graphql-mesh/blob/77311327ee1ba246adafd71dcbd3f658f8750305/packages/runtime/src/utils.ts#L153PRs are welcome ;)