-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test basic working. * Fix Graphql tests misnamed field. * Finalize graphene test porting. * Updates after rebase. * Remove unused import. * Expand tox matrix for graphene. * Fix py2 tests for graphene. * Fix py2 tests for graphene. * Remove unused code. * Final testing update. Co-authored-by: Uma Annamalai <[email protected]> * Minor testing tweaks. * Add testing for graphene schemas in fastapi. Co-authored-by: Uma Annamalai <[email protected]>
- Loading branch information
1 parent
2c83422
commit 4c5641c
Showing
10 changed files
with
834 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from graphene import ( | ||
ObjectType, | ||
Field, | ||
String, | ||
Schema, | ||
Mutation as GrapheneMutation, | ||
Int, | ||
List, | ||
NonNull, | ||
Union, | ||
) | ||
|
||
|
||
class Author(ObjectType): | ||
first_name = String() | ||
last_name = String() | ||
|
||
|
||
class Book(ObjectType): | ||
id = Int() | ||
name = String() | ||
isbn = String() | ||
author = Field(Author) | ||
branch = String() | ||
|
||
|
||
class Magazine(ObjectType): | ||
id = Int() | ||
name = String() | ||
issue = Int() | ||
branch = String() | ||
|
||
|
||
class Item(Union): | ||
class Meta: | ||
types = (Book, Magazine) | ||
|
||
|
||
class Library(ObjectType): | ||
id = Int() | ||
branch = String() | ||
magazine = Field(List(Magazine)) | ||
book = Field(List(Book)) | ||
|
||
|
||
Storage = List(String) | ||
|
||
|
||
|
||
authors = [ | ||
Author( | ||
first_name="New", | ||
last_name="Relic", | ||
), | ||
Author( | ||
first_name="Bob", | ||
last_name="Smith", | ||
), | ||
Author( | ||
first_name="Leslie", | ||
last_name="Jones", | ||
), | ||
] | ||
|
||
books = [ | ||
Book( | ||
id=1, | ||
name="Python Agent: The Book", | ||
isbn="a-fake-isbn", | ||
author=authors[0], | ||
branch="riverside", | ||
), | ||
Book( | ||
id=2, | ||
name="Ollies for O11y: A Sk8er's Guide to Observability", | ||
isbn="a-second-fake-isbn", | ||
author=authors[1], | ||
branch="downtown", | ||
), | ||
Book( | ||
id=3, | ||
name="[Redacted]", | ||
isbn="a-third-fake-isbn", | ||
author=authors[2], | ||
branch="riverside", | ||
), | ||
] | ||
|
||
magazines = [ | ||
Magazine(id=1, name="Reli Updates Weekly", issue=1, branch="riverside"), | ||
Magazine(id=2, name="Reli Updates Weekly", issue=2, branch="downtown"), | ||
Magazine(id=3, name="Node Weekly", issue=1, branch="riverside"), | ||
] | ||
|
||
|
||
libraries = ["riverside", "downtown"] | ||
libraries = [ | ||
Library( | ||
id=i + 1, | ||
branch=branch, | ||
magazine=[m for m in magazines if m.branch == branch], | ||
book=[b for b in books if b.branch == branch], | ||
) | ||
for i, branch in enumerate(libraries) | ||
] | ||
|
||
storage = [] | ||
|
||
|
||
|
||
class StorageAdd(GrapheneMutation): | ||
class Arguments: | ||
string = String(required=True) | ||
|
||
string = String() | ||
|
||
def mutate(parent, info, string): | ||
storage.append(string) | ||
return String(string=string) | ||
|
||
|
||
class Query(ObjectType): | ||
library = Field(Library, index=Int(required=True)) | ||
hello = String() | ||
search = Field(List(Item), contains=String(required=True)) | ||
echo = Field(String, echo=String(required=True)) | ||
storage = Storage | ||
error = String() | ||
|
||
def resolve_library(parent, info, index): | ||
# returns an object that represents a Person | ||
return libraries[index] | ||
|
||
def resolve_storage(parent, info): | ||
return storage | ||
|
||
def resolve_search(parent, info, contains): | ||
search_books = [b for b in books if contains in b.name] | ||
search_magazines = [m for m in magazines if contains in m.name] | ||
return search_books + search_magazines | ||
|
||
def resolve_hello(root, info): | ||
return "Hello!" | ||
|
||
def resolve_echo(root, info, echo): | ||
return echo | ||
|
||
def resolve_error(root, info): | ||
raise RuntimeError("Runtime Error!") | ||
|
||
error_non_null = Field(NonNull(String), resolver=resolve_error) | ||
|
||
|
||
class Mutation(ObjectType): | ||
storage_add = StorageAdd.Field() | ||
|
||
_target_application = Schema(query=Query, mutation=Mutation, auto_camelcase=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
import six | ||
from testing_support.fixtures import ( | ||
code_coverage_fixture, | ||
collector_agent_registration_fixture, | ||
collector_available_fixture, | ||
) | ||
|
||
_coverage_source = [ | ||
"newrelic.hooks.framework_graphql", | ||
] | ||
|
||
code_coverage = code_coverage_fixture(source=_coverage_source) | ||
|
||
_default_settings = { | ||
"transaction_tracer.explain_threshold": 0.0, | ||
"transaction_tracer.transaction_threshold": 0.0, | ||
"transaction_tracer.stack_trace_threshold": 0.0, | ||
"debug.log_data_collector_payloads": True, | ||
"debug.record_transaction_failure": True, | ||
} | ||
|
||
collector_agent_registration = collector_agent_registration_fixture( | ||
app_name="Python Agent Test (framework_graphql)", | ||
default_settings=_default_settings, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def app(): | ||
from _target_application import _target_application | ||
|
||
return _target_application | ||
|
||
|
||
if six.PY2: | ||
collect_ignore = ["test_application_async.py"] |
Oops, something went wrong.