timqian / gql-generator

Generate queries from graphql schema, used for writing api test.
MIT License
374 stars 93 forks source link

Less restrictive Query/Mutation/Subscription regex #61

Closed damau closed 2 years ago

damau commented 2 years ago

Thanks so much for this library!!!👏 It's ace.

Bug Fix

Schema

My server side schema plugin generates a schema as follows:

schema {
  query: RootQueryType
  mutation: RootMutationType
}

Expected

yarn gqlg --schemaFilePath ./codegen/schema.graphql --destDirPath ./src/generated/schema --depthLimit 4
# produces
src/generated/schema/mutations
src/generated/schema/query

Actual - fixed in this PR

yarn gqlg --schemaFilePath ./codegen/schema.graphql --destDirPath ./src/generated/schema --depthLimit 4
# produces
src/generated/schema/undefined

General Info

I imagine the above problem is fairly common given that my schema above is auto-generated (Absinthe - Elixir)

Additionally the regex is parsing only what comes from this schema object i.e:

gqlSchema.getQueryType().name = RootQueryType
gqlSchema.getMutationType().name = RootMutationType

So it should be fairly stable. Unless the below is common:

schema {
  query: RootQueryMutationType
  mutation: RootMutationQueryType
}

Though I hope not. I can add a stricter Regex if required. Or something not using a Regex if you like.

timqian commented 2 years ago

Thank you🎉 @damau

damau commented 2 years ago

Thanks @timqian