timqian / gql-generator

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

Infinite recursiveness #60

Open zvictor opened 2 years ago

zvictor commented 2 years ago

Gql-generator goes into infinite recursiveness once we add just 2 lines of code to the end of example/sampleTypeDef.graphql! CC @RvanderLaan

Steps to reproduce:

  1. Copy the code below to example/sampleTypeDef.graphql:
    
    type Query {
    user(id: Int!): User!
    members: [Member!] @deprecated(reason: "Test a deprecated query")
    }

type Mutation { signup( email: String! username: String! password: String! ): UserToken!

signin(
    email: String!
    password: String!
): String!

setConfig(
    prefs: PrefsInput
): Config!

sendMessage(
    message: String!
): String! @deprecated(reason: "Test a deprecated mutation")

}

input PrefsInput { language: String! }

type Config { language: String! level(domain: String!): Int! lastSeen(domain: String!): Int! theme(domain: String!): Int! }

type Subscription { UserUpdated(UserId: Int!): User }

type UserToken { token: String! user: User! }

type User { id: Int! username: String! email: String! createdAt: String! context: Context! details: UserDetails! address: String! @deprecated(reason: "Test a deprecated field") }

union UserDetails = Guest | Member | Premium

type Guest { region(language: String): String! }

type Member { address: String! }

type Premium { location: String! card: Card! }

type Card { number: String! type: [CardType!]! owner: User! # <------------------ ADDED --------------------- }

type CardType { key: String! }

type Context { user: User! # Circular ref domain: String! card: Card! # <------------------ ADDED --------------------- }



2. Run the tests or just `node index.js --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output`
zvictor commented 2 years ago

I think I solved it! šŸŽ‰ @timqian please decide on #59 so that I can base the solution for this issue on that refactoring or not. Once #59 is merged I will push the fix for this one šŸ˜Š