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

globby returns inconsistent order of found files #2311

Closed
yoavain-sundaysky opened this issue Aug 8, 2019 · 10 comments
Closed

globby returns inconsistent order of found files #2311

yoavain-sundaysky opened this issue Aug 8, 2019 · 10 comments
Labels
core Related to codegen core/cli waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@yoavain-sundaysky
Copy link

Describe the bug
Each time I'm running the graphql-codegen, I get a different result.
All results are valid, but order of types changes.

This creates 2 problems for us.

  1. We think we need to commit generated files each time we run the tool.
  2. I wrote a test that makes sure all developers are running the tool and commit the new generated files, and the test is broken now..

I went over your changes from 1.4 to 1.5 and my guess is this:
You replaced glob with globby, and from a quick search I found this bug that suggests that globby results are non-deterministic:
sindresorhus/globby#131

To Reproduce

  1. Run graphql-codegen, commit result.
  2. Run graphql-codegen again, check for changes.

Our schema is too complex to share, but if you can't reproduce it, I'll try to create a live sandbox.

My codegen.yml config file:

overwrite: true
schema:
  - ./server/graphql/**/*.graphql
documents:
  - ./client/**/*.graphql
generates:
  ./common/graphqlGeneratedTypes/graphqlClient.tsx:
    config:
      withComponent: false
      typesPrefix: "GqlClient"
      nonOptionalTypename: true
      namingConvention:
        typeNames: change-case#pascalCase
        enumValues: change-case#upperCase
    plugins:
      - typescript
      - typescript-operations
      - typescript-react-apollo

Expected behavior
consistent generated files.

Environment:

  • OS: Windows
  • @graphql-codegen/1.5.0:
  • NodeJS: 10.x
@ardatan
Copy link
Collaborator

ardatan commented Aug 8, 2019

What is the difference between outputs? There are some changes in 1.5, so that might cause a diff. Is there any specific issue like TS error or something?

@ardatan ardatan added the waiting-for-answer Waiting for answer from author label Aug 8, 2019
@yoavain-sundaysky
Copy link
Author

@ardatan the issue is not between 1.4 and 1.5.
I'm okay with the additions of the 1.5 version.
Problem is the non-deterministic result.
Types are ordered differently every time running the codegen of version 1.5.

@ardatan ardatan added bug core Related to codegen core/cli and removed waiting-for-answer Waiting for answer from author labels Aug 8, 2019
@dotansimha
Copy link
Owner

dotansimha commented Aug 11, 2019

Hi @yoavain-sundaysky !

Why should the order matter? the generated file shouldn't go to source-control, so you shouldn't get effected by the order of the generated output.

We are using globby now because it provides a better solution for specifying multiple glob patterns, and it's easier to exclude files with it.

I'm not sure if we can introduce a solution for that at the moment (maybe just sorting it will work?) - but if your generated files will be excluded from source-control - you shouldn't get effected by that.

@dotansimha dotansimha added core Related to codegen core/cli and removed bug core Related to codegen core/cli labels Aug 11, 2019
@dotansimha dotansimha changed the title codegen output changes between run globby returns inconsistent order of found files Aug 11, 2019
@dotansimha dotansimha mentioned this issue Aug 11, 2019
@dotansimha
Copy link
Owner

@yoavain-sundaysky I added documents sort by file path, so it might solve this issue.
Can you please try 1.5.1-alpha-a6dbc965.21?

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Aug 11, 2019
@jkillian
Copy link

jkillian commented Aug 12, 2019

Just FWIW, we also check in our generated types! And then we have CI generate them as well, and assert that the generated types are equal to the checked-in ones. This is a nice sanity check for us to make sure that everyone is operating with a correct version of types and has the correct local environment.

In other words, it's necessary for us to have a stable file generation process also. So thanks for the fix!

@yoavain-sundaysky
Copy link
Author

Thanks @dotansimha,
1.5.1-alpha-a6dbc965.21 generated files seems to be consistent again.

To answer your previous questions, we currently have these generated files committed (maybe it's bad practice. I'm not sure). Because of that, we have a test that makes sure that if someone changes schema or document files, he can't forget to commit these files...

Thanks for the fix

@dotansimha
Copy link
Owner

Fixed in 1.6.0

@yoavain-sundaysky
Copy link
Author

yoavain-sundaysky commented Sep 2, 2019

I'm still having issues with consistency. This time it's in the fields order. Not sure if it's the same issue.

Example:
_?: Maybe<Scalars["Boolean"]>; (under GqlQuery)
appears sometimes at the beginning and sometimes at the end.

Example 2:
Order of ResolverTypeWrapper under GqlResolversTypes changes between executions.

Example 3:
Order of fields of GqlResolversParentTypes changes between executions.

Tested on 1.7.0

@dotansimha?

@dotansimha dotansimha reopened this Sep 5, 2019
@dotansimha
Copy link
Owner

@yoavain-sundaysky let's track this here: #2402

@dotansimha
Copy link
Owner

@yoavain-sundaysky note that we fixed that, you can try the latest alpha.
We'll release 1.8.0 soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

4 participants