eslint-plugin-graphql icon indicating copy to clipboard operation
eslint-plugin-graphql copied to clipboard

Add error for duplicate keys

Open zackify opened this issue 8 years ago • 2 comments
trafficstars

This may sound kind of dumb, but it would still be nice to have. If I put the same key twice inside of a query, could we make it display an error message? If so, I’d be interested in making a PR

zackify avatar Sep 29 '17 04:09 zackify

@zackify sure, that sounds like a reasonable thing to add! happy to accept a PR

jnwng avatar Nov 09 '17 16:11 jnwng

Think you can help me out a bit? Never messed with the graphql validators before. Looks like i can add something like this to the rules list:

'no-duplicate-variables': {
    meta: {
      schema: {
        type: 'array',
        minLength: 1,
        items: _extends(
          {
            additionalProperties: false,
            properties: _extends({}, defaultRuleProperties, {
              env: {
                enum: ['lokka', 'relay', 'apollo', 'literal'],
              },
              requiredFields: {
                type: 'array',
                items: {
                  type: 'string',
                },
              },
            }),
          },
          schemaPropsExclusiveness
        ),
      },
    },
    create: function create(context) {
      return createRule(context, function(optionGroup) {
        return parseOptions(
          _extends(
            {
              validators: ['UniqueVariableNames'],
            },
            optionGroup
          )
        );
      });
    },
  },

But this doesn't work, I feel like I'm barely missing something (hopefully :p)

zackify avatar Nov 10 '17 15:11 zackify