question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: unique-enum-value-names throws "Duplicate "graphql" modules exception

See original GitHub issue

graphql-eslint: v0.7.2

I checked the package-lock, there’s only one version of graphql referenced: v15.5.0 (latest)

files: ['*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
parserOptions: {
  schema: './schema/**/*.graphql',
},
plugins: ['@graphql-eslint'],
rules: {
  '@graphql-eslint/unique-enum-value-names': 'error',
},
/Users/daniel/graphql-schema/schema/StatementState.graphql
  0:1  error  Cannot use GraphQLEnumType "StatementState" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

https://yarnpkg.com/en/docs/selective-version-resolutions

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results  @graphql-eslint/unique-enum-value-names

I tried another graphql validation rule. interestingly, e.g. rule @graphql-eslint/variables-are-input-types works without an error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dotansimhacommented, Feb 2, 2021

Fixed in @graphql-eslint/eslint-plugin@0.8.0

1reaction
dnalborczykcommented, Jan 29, 2021

I think I found the problem: graphql (parts of it) is being bundled with the package. I assume this is not intentional?

from: index.cjs.js

/**
 * Unique enum value names
 *
 * A GraphQL enum type is only valid if all its values are uniquely named.
 */
function UniqueEnumValueNamesRule(context) {
  var schema = context.getSchema();
  var existingTypeMap = schema ? schema.getTypeMap() : Object.create(null);
  var knownValueNames = Object.create(null);
  return {
    EnumTypeDefinition: checkValueUniqueness,
    EnumTypeExtension: checkValueUniqueness
  };

  function checkValueUniqueness(node) {
    var _node$values;

    var typeName = node.name.value;

    if (!knownValueNames[typeName]) {
      knownValueNames[typeName] = Object.create(null);
    } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')


    var valueNodes = (_node$values = node.values) !== null && _node$values !== void 0 ? _node$values : [];
    var valueNames = knownValueNames[typeName];

    for (var _i2 = 0; _i2 < valueNodes.length; _i2++) {
      var valueDef = valueNodes[_i2];
      var valueName = valueDef.name.value;
      var existingType = existingTypeMap[typeName];

      if (isEnumType(existingType) && existingType.getValue(valueName)) {
        context.reportError(new GraphQLError("Enum value \"".concat(typeName, ".").concat(valueName, "\" already exists in the schema. It cannot also be defined in this type extension."), valueDef.name));
      } else if (valueNames[valueName]) {
        context.reportError(new GraphQLError("Enum value \"".concat(typeName, ".").concat(valueName, "\" can only be defined once."), [valueNames[valueName], valueDef.name]));
      } else {
        valueNames[valueName] = valueDef.name;
      }
    }

    return false;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Duplicate "graphql" modules · Issue #211 - GitHub
If different versions of "graphql" are the dependencies of other relied on modules, use "resolutions" to ensure only one version is installed.
Read more >
Duplicate "graphql" modules cannot be used - Stack Overflow
I encountered this error and resolved it using the following steps: list all available instances of graphql package to check for dependences.
Read more >
graphql-eslint - Bountysource
ESLint parser, plugin and set rules for GraphQL (for schema and operations). ... bug: unique-enum-value-names throws "Duplicate "graphql" modules exception ...
Read more >
ERROR: Duplicate "graphql" modules cannot be used at the ...
I'm trying to create a new code-first NextJS demo using the JSS initializer for experimental purposes only: enter image description here.
Read more >
Duplicate GraphQL Error Out of Nowhere - Questions - Prisma 1
Duplicate “graphql” modules cannot be used at the same time since ▸ different ▸ versions may have different capabilities and behavior.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found