Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.03k stars 99 forks source link

Inconsistent behavior for directives #247

Closed kantum closed 1 year ago

kantum commented 1 year ago

Describe the bug On a big schema from Hasura, directives are sometimes added, but disappear if genqlient is run again.

To Reproduce See https://github.com/kantum/genqlient-bug

Expected behavior Running genqlient twice should give the same result. Directives should be applied.

genqlient version v0.5.0

kantum commented 1 year ago

I solved it:

It was about this line in genqlient.yaml:

operations:
- operations/**/*.graphql

Apparently, I have to explicitly specify a name for files.

This works:

operations:
- operations/**/InsertUserOne.graphql

Maybe related to #167

benjaminjkraft commented 1 year ago

Thanks for the repro!

The real problem here is described in #123. Specifically, you have inconsistent directives on UserInsertInput in each operation -- all of the operations ultimately refer to UserInsertInput but only InsertUserOne has the directive. Unfortunately at the moment the behavior is we use whichever set of directives we see first, which when you combine it with globbing is potentially nondeterministic (it depends on the order that we get the files from the file system). Anyway, the fix is to put that directive on all your queries that might refer to UserInsertInput; fixing #123 would give you validation to tell you that explicitly.

(With that said, you're right that as described in #167 your ** isn't doing anything! But that doesn't matter since you just have one level of nested directories anyway, so the equivalent operations/*/*.graphql will do fine.)