ardatan / graphql-tools

:wrench: Utility library for GraphQL to build, stitch and mock GraphQL schemas in the SDL-first approach
https://www.graphql-tools.com
MIT License
5.34k stars 809 forks source link

Make @graphl-tools/utils ESM use ESM version of graphql #4760

Closed cyberwombat closed 1 year ago

cyberwombat commented 1 year ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow


In an ESM project there is a conflict with locally used graphql module (which will be in esm mode) and the use of @graphwl-tools/utils which imports the CJS version of graphql resulting in a multiple graphql modules error.

This SO question and accepted answer illustrate the issue and solution.

To Reproduce In a pure esm project, use both graphql-tools (for ex I use makeExecutableSchema as well as directly use the graphql package.

I can confirm the accepted SO solution works. I think something similar applied (in this case I am looking at the ctranspiled @graphql-tols/utlls/index.mjs file:

import { parse, isNonNullType, GraphQLError, Kind, valueFromAST, print, isObjectType, isListType, isSpecifiedDirective, astFromValue, isSpecifiedScalarType, isIntrospectionType, isInterfaceType, isUnionType, isInputObjectType, isEnumType, isScalarType, GraphQLDeprecatedDirective, specifiedRules, concatAST, validate, buildClientSchema, visit, TokenKind, Source, isTypeSystemDefinitionNode, getNamedType, GraphQLString, GraphQLNonNull, GraphQLList, GraphQLID, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLObjectType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLDirective, GraphQLUnionType, GraphQLEnumType, GraphQLScalarType, isNamedType, getNullableType, isLeafType, GraphQLSchema, isDirective, isCompositeType, doTypesOverlap, getDirectiveValues, GraphQLSkipDirective, GraphQLIncludeDirective, typeFromAST, isAbstractType, getOperationAST, getOperationRootType, TypeNameMetaFieldDef, buildASTSchema } from 'graphql'; // Perhaps this is issue?

I didn't provide a sandbox as my setup is quite complex to replicate but I think/hope issue is obvious.

Thanks

ardatan commented 1 year ago

I think we still need a reproduction on a sandbox :)

cyberwombat commented 1 year ago

I was afraid you'd say that :). Do you have a starter sandbox with the use of makeExecutableSchema?

ardatan commented 1 year ago

No we don't have any. It is just a javascript file with makeExecutableSchema :)

eduhenke commented 1 year ago

I'm also getting this error

ardatan commented 1 year ago

Maybe you have an older version because we don't have files with "mjs" extension anymore in the newer versions; https://unpkg.com/@graphql-tools/utils@8.12.0/package.json

cyberwombat commented 1 year ago

Evidently yarn doesn't remove any code and just adds new versions on top of old one. Not sure what thats about. But I deleted my entire node modules and rebuild - there is indeed no longer an index.mjs but problem persists. I am rather baffled. Basically using the GraphQLSchema type from graphpl package is not accepted by the schema executor saying its using a different GraphQLSchema. The current patch as indicated in SO solutions "fixes" it but I haven't yet tracked what needs changing to load the esm module.

ardatan commented 1 year ago

Also graphql-tools npm package has been deprecated and will no longer receive updates. You should use scoped packages like @graphql-tools/schema. Closing this issue now since no reproduction is provided and it is actually related to an older deprecated package/version.