2

The django graphene documentation shows a test example like this:

class MyFancyTestCase(GraphQLTestCase):
    def test_some_query(self):
        response = self.query(
            '''
            query {
                myModel {
                    id
                    name
                }
            }
            ''',
            op_name='myModel'
        )

        content = json.loads(response.content)

        # This validates the status code and if you get errors
        self.assertResponseNoErrors(response)

        # Add some more asserts if you like
        ...

They don't have any API documentation for what op_name is, and what we should set it as. I tried to set it to my query name, but get the error:

[{'message': 'Unknown operation named "myQuery".'}]
coler-j
  • 1,791
  • 1
  • 27
  • 57
  • The API documentation says: "If the query is a mutation or named query, you must supply the op_name. For annon queries ("{ ... }"), should be None (default)", but I am using the name that I have supplied. – coler-j Jan 16 '21 at 21:44

2 Answers2

2

Operation name is only needed when there are multiple operations in the query string. You only have one operation so the default (None) is fine.

https://docs.graphene-python.org/en/latest/execution/execute/#operation-name

Benj Fayle
  • 21
  • 2
0

As per my comment:

If the query is a mutation or named query, you must supply the op_name. For annon queries ("{ ... }"), should be None (default)

I am not sure how to create a "named query" with django graphene, but apparently my query is NOT a named query. Leaving op_name as None got my query to work via my unit test.

coler-j
  • 1,791
  • 1
  • 27
  • 57