-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I generate API from my .graphql files without generating entire api? #39
Comments
@jasonbobier Could you please explain your use-case more in detail? What do you specifically mean by - |
Right now, the codegen generates api for everything in the schema, including lots of stuff that I will never use. I want to be able to have .graphql files that I write that contain only my necessary queries. For example, say you had a schema with something like this:
(assume the other types are large and complicated) and I just want to get my email address with a query in a .graphql file like this:
Running codegen will generate the entire schema API adding lots and lots of needless code and potential namespace issues instead of just the code for my email query. I was able to get this to work by using the hack that I mentioned above, but it produces errors and is a totally hack. It would be better if the API produced was only what was in my .graphql files instead of the entire schema. Especially since many of these schemas are huge. |
@jasonbobier See Below projects:
myProject:
schemaPath: amplify/backend/api/myProject/build/schema.graphql
includes:
- src/customFolder/**/*.graphql # include your custom schema here
excludes:
- ./amplify/**
.... |
This isn't a custom schema though. These are just normal GraphQL client queries, mutations, and subscriptions. The while point of GraphQL is that the client can ask for only what it needs. Having the codegen download the real schema to use when validating client queries during codegen is what we want to happen, but we don't want the codegen to generate code for the entire schema. Just the queries that we specify in the .graphql files. |
@jasonbobier just wanted to let you know that we've publish an RFC to address this and other code generation issues. Would love to have your feedback! aws-amplify/amplify-cli#6898 |
Thanks! I'll take a look when I get a moment. The contract that I was working on with this ended a year ago though, so my memories are vague. :) |
** Which Category is your question related to? **
amplify codegen for iOS
** What AWS Services are you utilizing? **
Appsync
** Provide additional details e.g. code snippets **
I don't want api for the entire schema polluting my namespace. I want API just for the .graphql file that I generate. How do I do this?
I was able to get this to work by moving the schema out of my ../graphql directory, putting my .graphql files in the directory, and then using:
amplify codegen --max-depth graphql/*.graphql
It generates the API.swift (which works!), but then errors out with:
uncaughtException: GraphQL schema file should contain a valid GraphQL introspection query result date=Fri Aug 23 2019 12:30:41 GMT+0200 (Central European Summer Time), pid=96247, uid=501, gid=20, cwd=/Users/jason/Documents/projects/tensil/bettercam-ios/Bettercam/Server/GraphQLAPI, execPath=/usr/local/bin/node, version=v10.16.3, argv=[/usr/local/bin/node, /usr/local/bin/amplify, codegen, --max-depth, graphql/GroupsTableViewControllerViewModel.graphql], rss=307851264, heapTotal=239886336, heapUsed=204516848, external=50348145, loadavg=[1.81005859375, 1.89892578125, 1.77294921875], uptime=676048, trace=[column=11, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-docs-generator/lib/generator/src/generator/generate.ts, function=Object.generate [as default], line=20, method=generate [as default], native=false, column=57, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-docs-generator/lib/src/index.ts, function=generate, line=40, method=null, native=false, column=11, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/commands/statements.js, function=projects.forEach, line=32, method=forEach, native=false, column=7, file=internal/process/next_tick.js, function=process._tickCallback, line=68, method=_tickCallback, native=false], stack=[Error: GraphQL schema file should contain a valid GraphQL introspection query result, at Object.generate [as default] (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-docs-generator/lib/generator/src/generator/generate.ts:20:11), at generate (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-graphql-docs-generator/lib/src/index.ts:40:57), at projects.forEach (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/commands/statements.js:32:11), at process._tickCallback (internal/process/next_tick.js:68:7)]
The text was updated successfully, but these errors were encountered: