Skip to content
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

Apollo + GraphQL code generator showcase #11

Closed

Conversation

LukasKalbertodt
Copy link
Member

@LukasKalbertodt LukasKalbertodt commented Jul 21, 2020

This PR serves just as an example how the Apollo GraphQL JS library works in combination with the "GraphQL Code generator". This PR is based on #10. See this document for context.

This is just for getting familiar with all GraphQL tooling/libraries
and will be completely removed later.
It works, but one thing is still problematic: the `gql` JS template
does not generate TS typings. There are a few way to pre-process gql,
but none of those generates types either I think. We can manually
specify types, but this feels like duplication, as the schema already
defines all the types.

Maybe specifying types in the frontend again is good to make sure
frontend and backend agree on the types. But in that case we would like
to have a test to check that both agree on the types. So in either way,
we need some way to generate types from the schema and `gql`
invocations.
This more or less solves one problem of the "Apollo only" approach.
Apparently it is also possible to use the relay compiler with the
"GraphQL code generator" to optimize queries.

Disadvantages of this approach:
- Yet another CLI to run as build step
- The `data` type always includes `| undefined` due to Apollo sometimes
  returning that (e.g. when passing `skip: true`). This could be
  annoying to always assert it is not `undefined`.
- All generated code is in one file, so when defining query names, one
  has to look out for name clashes. It would be nicer if for each
  `.graphql` file, a tsx file is generated to have locally scoped
  names. We can have that, if we add an entry for each file in
  `codegen.yml`, but that's meh.
- We need the schema file somewhere.
@LukasKalbertodt
Copy link
Member Author

Superseded by #21

@LukasKalbertodt LukasKalbertodt deleted the gql-codegen-showcase branch August 5, 2020 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant