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

Schema error when using same type from different type sources #1064

Closed
bombillazo opened this issue Sep 20, 2021 · 0 comments
Closed

Schema error when using same type from different type sources #1064

bombillazo opened this issue Sep 20, 2021 · 0 comments

Comments

@bombillazo
Copy link

bombillazo commented Sep 20, 2021

Describe the bug
Building a schema where a scalar type was imported via SDL and the same scalar was used to create a GraphQL.js Object Type will fail. For example, using the DateTime scalar would fail with the following error:

Schema must contain uniquely named types but contains multiple types named "DateTime".

Doing some debugging, when GraphQL builds the list of types in the collectReferencedTypes function, it is adding both DateTime types into the schema typeSet. This causes the schema building in step 5 (below) to fail.

Seems the schema builder is seeing each DateTime as different types. I examined both DateTime scalar type objects as they passed through the building process and they were pretty much identical except the one imported from the SDL file had the astNode type property with data on where in the SDL file the definition was located, while the DateTime type created programmatically had astNode as undefined. It is not recognizing/reconciling the fact that it is supposed to be the same type.

To Reproduce

  1. Create an SDL file and use a graphql-scalar type (DateTime in this example):
import { gql } from 'graphql-modules';

export const dummyTypeDef = `gql
scalar DateTime

type DummyType {
  id: String
  myDate: DateTime
}
`;
  1. Import dummyTypeDef and create GraphQL schema from SDL definition
  2. Get GraphQL.js object from SDL schema
  3. Create a new GraphQLObjectType that uses GraphQLDateTime
  4. Create new Schema from GraphQLObjectTypes
  5. Output printed schema to see SDL result
import { buildASTSchema , GraphQLObjectType, printSchema } from 'graphql';
import { dummyTypeDef } from './dummyType';
import { GraphQLDateTime } from 'graphql-scalars';

const schemaObject = buildASTSchema(dummyTypeDef ); // step 2
const dummyObjectType = schemaObject.getType('DummyType')! as GraphQLObjectType; // step 3
// step 4
const secondType = new GraphQLObjectType({
  name: 'secondType',
  fields: {
    id: { type: GraphQLString },
    otherDate: { type: GraphQLDateTime },
  }
});
// step 5
const myschema = new GraphQLSchema({
  types: [dummyObjectType, secondType]
});
console.log(printSchema(myschema)); // step 6

Expected behavior
Schema gets built and scalar types are reconciled even when one was imported via SDL definition and the other was created with GraphQL.js.

Environment:

  • OS: Windows 10
  • GraphQL Scalars Version: 1.10.1
  • NodeJS: 14.17.3

Additional context
Work-around: Defined your SDL in GraphQL.js

@bombillazo bombillazo closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2023
@theguild-bot theguild-bot mentioned this issue Apr 24, 2023
37 tasks
@theguild-bot theguild-bot mentioned this issue Oct 26, 2023
36 tasks
@theguild-bot theguild-bot mentioned this issue Feb 5, 2024
36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant