booster icon indicating copy to clipboard operation
booster copied to clipboard

GraphQL generator fails when custom types are used multiple times

Open NickSeagull opened this issue 4 years ago • 0 comments

Bug Report

Current Behavior

I've created a custom type called Skill that is being used in multiple commands, and when trying to get the GraphQL schema, the graphql-handler lambda fails with the following error:

{
    "errorType": "Error",
    "errorMessage": "Schema must contain uniquely named types but contains multiple types named \"SkillInput\".",
    "stack": [
        "Error: Schema must contain uniquely named types but contains multiple types named \"SkillInput\".",
        "    at new GraphQLSchema (/var/task/node_modules/graphql/type/schema.js:194:15)",
        "    at GraphQLGenerator.generateSchema (/var/task/node_modules/@boostercloud/framework-core/dist/services/graphql/graphql-generator.js:29:16)",
        "    at new BoosterGraphQLDispatcher (/var/task/node_modules/@boostercloud/framework-core/dist/booster-graphql-dispatcher.js:18:89)",
        "    at Function.serveGraphQL (/var/task/node_modules/@boostercloud/framework-core/dist/booster.js:88:16)",
        "    at Runtime.boosterServeGraphQL [as handler] (/var/task/node_modules/@boostercloud/framework-core/dist/booster.js:112:20)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}

Expected behavior

Lambda doesn't fail, and I can get my schema/use GraphQL.

Possible Solution

I believe this is because we don't check for existing types at https://github.com/boostercloud/booster/blob/ca350d092bb814ae770fc3401e7d01afbfd77a0b/packages/framework-core/src/services/graphql/graphql-type-informer.ts#L109:10

A possible solution would be to return if the type is already registered in the schema

Additional information

Environment

@boostercloud/cli/0.17.0 darwin-x64 node-v14.17.0

NickSeagull avatar Jul 12 '21 18:07 NickSeagull