0

When you post an query with syntax errors graphql/graphene makes suggestions to you. By example, sending "i", it suggest "ID".

query{
  users{
        i
  }
}
{
  "errors": [
    {
      "message": "Cannot query field \"i\" on type \"User\". Did you mean \"id\"?",
      "locations": [
        {
          "line": 5,
          "column": 9
        }
      ]
    }
  ]
}

Can suggestions be disabled?

More info: Syntax analysis who add suggestions is executed before the middlewares. Apparently suggestions are made by ScalarLeafsRule class.

cristhiam
  • 496
  • 1
  • 4
  • 17

1 Answers1

0

Ok, people in graphql-core github repo is awesome, they helped to me to solve this.

So graphql-core has two relevant versions, 3 (current) and 2.3.2 (legacy). For graphql-core 3, quoting to Cito

Ok, if you want to keep it closed and also disable introspection it makes a little more sense. I suggest you simply set graphql.pyutils.did_you_mean.MAX_LENGTH = 0. I just commited a small change ffdf1b3 that makes this work a bit better.

You can also ask over at https://github.com/graphql/graphql-js/issues if they want to add some functionality to support your use case. From there it would be ported back here.

For legacy version:

from graphql.validation import rules
def get_empty_suggested_field_names(schema, graphql_type, field_name):
    return []
def get_empty_suggested_type_names(schema, output_type, field_name):
    return []
rules.fields_on_correct_type.get_suggested_field_names = get_empty_suggested_field_names
rules.fields_on_correct_type.get_suggested_type_names = get_empty_suggested_type_n

You can place it on django settings file.

Please follow all the thread on https://github.com/graphql-python/graphql-core/issues/97

cristhiam
  • 496
  • 1
  • 4
  • 17