Skip to content

Change deprecated execute() arguments to new ones #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/execution/execute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For executing a query a schema, you can directly call the ``execute`` method on
Context
_______

You can pass context to a query via ``context_value``.
You can pass context to a query via ``context``.


.. code:: python
Expand All @@ -28,14 +28,14 @@ You can pass context to a query via ``context_value``.
return info.context.get('name')

schema = graphene.Schema(Query)
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
result = schema.execute('{ name }', context={'name': 'Syrus'})



Variables
_______

You can pass variables to a query via ``variable_values``.
You can pass variables to a query via ``variables``.


.. code:: python
Expand All @@ -55,5 +55,5 @@ You can pass variables to a query via ``variable_values``.
lastName
}
}''',
variable_values={'id': 12},
variables={'id': 12},
)
4 changes: 2 additions & 2 deletions docs/testing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Execute parameters
~~~~~~~~~~~~~~~~~~

You can also add extra keyword arguments to the ``execute`` method, such as
``context_value``, ``root_value``, ``variable_values``, ...:
``context``, ``root``, ``variables``, ...:


.. code:: python
Expand All @@ -63,7 +63,7 @@ You can also add extra keyword arguments to the ``execute`` method, such as

def test_hey():
client = Client(my_schema)
executed = client.execute('''{ hey }''', context_value={'user': 'Peter'})
executed = client.execute('''{ hey }''', context={'user': 'Peter'})
assert executed == {
'data': {
'hey': 'hello Peter!'
Expand Down
4 changes: 2 additions & 2 deletions examples/context_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def resolve_me(self, info):


def test_query():
result = schema.execute(query, context_value={"user": User(id="1", name="Syrus")})
result = schema.execute(query, context={"user": User(id="1", name="Syrus")})
assert not result.errors
assert result.data == {"me": {"id": "1", "name": "Syrus"}}


if __name__ == "__main__":
result = schema.execute(query, context_value={"user": User(id="X", name="Console")})
result = schema.execute(query, context={"user": User(id="X", name="Console")})
print(result.data["me"])
6 changes: 3 additions & 3 deletions examples/starwars/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_fetch_some_id_query(snapshot):
}
"""
params = {"someId": "1000"}
snapshot.assert_match(client.execute(query, variable_values=params))
snapshot.assert_match(client.execute(query, variables=params))


def test_fetch_some_id_query2(snapshot):
Expand All @@ -84,7 +84,7 @@ def test_fetch_some_id_query2(snapshot):
}
"""
params = {"someId": "1002"}
snapshot.assert_match(client.execute(query, variable_values=params))
snapshot.assert_match(client.execute(query, variables=params))


def test_invalid_id_query(snapshot):
Expand All @@ -96,7 +96,7 @@ def test_invalid_id_query(snapshot):
}
"""
params = {"id": "not a valid id"}
snapshot.assert_match(client.execute(query, variable_values=params))
snapshot.assert_match(client.execute(query, variables=params))


def test_fetch_luke_aliased(snapshot):
Expand Down
8 changes: 3 additions & 5 deletions graphene/types/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_datetime_query_variable():

result = schema.execute(
"""query Test($date: DateTime){ datetime(in: $date) }""",
variable_values={"date": isoformat},
variables={"date": isoformat},
)
assert not result.errors
assert result.data == {"datetime": isoformat}
Expand All @@ -101,8 +101,7 @@ def test_date_query_variable():
isoformat = now.isoformat()

result = schema.execute(
"""query Test($date: Date){ date(in: $date) }""",
variable_values={"date": isoformat},
"""query Test($date: Date){ date(in: $date) }""", variables={"date": isoformat}
)
assert not result.errors
assert result.data == {"date": isoformat}
Expand All @@ -114,8 +113,7 @@ def test_time_query_variable():
isoformat = time.isoformat()

result = schema.execute(
"""query Test($time: Time){ time(at: $time) }""",
variable_values={"time": isoformat},
"""query Test($time: Time){ time(at: $time) }""", variables={"time": isoformat}
)
assert not result.errors
assert result.data == {"time": isoformat}
2 changes: 1 addition & 1 deletion graphene/types/tests/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_decimal_string_query_variable():

result = schema.execute(
"""query Test($decimal: Decimal){ decimal(input: $decimal) }""",
variable_values={"decimal": decimal_value},
variables={"decimal": decimal_value},
)
assert not result.errors
assert result.data == {"decimal": str(decimal_value)}
Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_generic_query_variable():
]:
result = schema.execute(
"""query Test($generic: GenericScalar){ generic(input: $generic) }""",
variable_values={"generic": generic_value},
variables={"generic": generic_value},
)
assert not result.errors
assert result.data == {"generic": generic_value}
Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_jsonstring_query_variable():

result = schema.execute(
"""query Test($json: JSONString){ json(input: $json) }""",
variable_values={"json": json_value},
variables={"json": json_value},
)
assert not result.errors
assert result.data == {"json": json_value}
2 changes: 1 addition & 1 deletion graphene/types/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def resolve_info(self, info):
assert not result.errors
assert result.data == {"annotated": "base-self"}

result = test_schema.execute("{ context }", "base", context_value=context)
result = test_schema.execute("{ context }", "base", context=context)
assert not result.errors
assert result.data == {"context": "base-context"}

Expand Down
2 changes: 1 addition & 1 deletion graphene/types/tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_uuidstring_query_variable():

result = schema.execute(
"""query Test($uuid: UUID){ uuid(input: $uuid) }""",
variable_values={"uuid": uuid_value},
variables={"uuid": uuid_value},
)
assert not result.errors
assert result.data == {"uuid": uuid_value}