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

Add passthrough schema config support with GQL Codegen #650

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

comp615
Copy link
Contributor

@comp615 comp615 commented Mar 21, 2023

Problem (#649)
GQLCodeGen supports several formats for the schema files used to do codegen. This include formats like remote URLs or TS/JS files that generate the schema.

The way Graphql-Let works today, its config is more or less directly passed through to the underlying GQLCodeGen CLI. This means that if you set your config to something like a remote file or TS file, the schema will actually be correctly generated.

The problem arises when you change that schema and re-run codegen. Before the config is passed through to the underlying CLI, graphql-let does some hashing / processing on it to determine if it should be run. The issue is that specific processing only handles literal files. If you browse the code, you can see there's a TODO and it filters out URLs. For TS/JS files...it can be very misleading because it will work, but it will actually hash the file itself (not the result of running the file which actually makes the schema)

This both:

  • Leads to situations where caching is improperly handled and does not appear to regenerate
  • Decreases overall API compatibility with CodeGen

Solution
If we look inside Codegen, we can see it uses several loaders and tools (all readily available) to parse the schemas. These loaders handle everything from traversing globbed patterns, to fetching remote files, and more.

By leveraging the same underlying parsers, we can effectively grab the actual schema (from just the schema config) and hash that content. This should give us a more accurate representation of the hash and when the schema has changed for more complex formats and should provide consistent behavior with the underlying GraphQLCodegen library

NOTE: I removed the Prisma loader because it is not Node 12 compatible.

NOTE: This is not mergable right now since the schema printing is too heavy; it won't work well with the loader functionality. There likely needs to be some memoization sitting in front of the loader, but we have no way to tell when a file changes and we need to rescan it.

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