Apollo-tooling: double star (**) in glob does not recursively include subdirectories

Created on 15 Mar 2018  路  4Comments  路  Source: apollographql/apollo-tooling

I have a directory structure like:

  mutations
    mutation_a.graphql
    mutation_b.graphql
  queries
    query_1.graphql
  fragments
    users
      user_fragment_x.graphql
      user_fragment_y.graphql

where, for example, one of the mutations has

#import ../fragments/users/user_fragment_x.graphql

I run codegen as follows:

apollo-codegen generate app/lib/apollo/graphql/**/*.graphql --schema app/lib/apollo/generated/schema.json

Which I expect to compile all the schema and fragments.

However, I get this error:

.../mutations/mutation_a.graphql: Unknown fragment "UserX".

If I run codegen as follows:

apollo-codegen app/lib/apollo/graphql/**/**/*.graphql generate app/lib/apollo/graphql/**/*.graphql --schema app/lib/apollo/generated/schema.json

(note the additional **/**/* syntax) the command completes successfully.

My expectation is that double star includes all directories recursively, matching what I believe to be the standard for that glob syntax, and mirroring, for example nodemon, but it appears to only include directories one level deep.

Most helpful comment

I was having this issue and a combination of upgrading bash and adding quotes solved it. My working command in package.json looks like this:

"apollo:codegen": "apollo-codegen generate \"src/**/*.{ts,tsx}\" --schema schema.json --target typescript --output otypes.ts --addTypename"

All 4 comments

I was having this issue and a combination of upgrading bash and adding quotes solved it. My working command in package.json looks like this:

"apollo:codegen": "apollo-codegen generate \"src/**/*.{ts,tsx}\" --schema schema.json --target typescript --output otypes.ts --addTypename"

Thank you for the tip :) When I do that, each file is added in such a way that they appear to be processed individually. Because I have client-side schema definitions to work around @client directive issues, that leads to The ObjectInput definition is not executable errors. For whatever reason, keeping the definition unquoted, and with both glob formats works.

Update: This was in fact because it was now including an additional graphql file that only had inputs and types. So, it works, thanks!

Adding quotes was the magic I needed!

Closing, given the existence of a simple workaround.

Was this page helpful?
0 / 5 - 0 ratings