mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 11:03:58 +03:00
Add SDL example
This commit is contained in:
parent
2fbe0a67af
commit
730688916e
|
@ -1,6 +1,7 @@
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from graphql import parse, build_ast_schema
|
||||||
from graphql.type import (
|
from graphql.type import (
|
||||||
GraphQLArgument,
|
GraphQLArgument,
|
||||||
GraphQLEnumType,
|
GraphQLEnumType,
|
||||||
|
@ -392,3 +393,39 @@ def test_graphql_type_union():
|
||||||
)
|
)
|
||||||
assert not results.errors
|
assert not results.errors
|
||||||
assert results.data == {"myUnion": {"__typename": "MyGraphQLType"}}
|
assert results.data == {"myUnion": {"__typename": "MyGraphQLType"}}
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_type_from_sdl():
|
||||||
|
types = """
|
||||||
|
type Pet {
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type User {
|
||||||
|
name: String!
|
||||||
|
pets: [Pet!]!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
ast_document = parse(types)
|
||||||
|
sdl_schema = build_ast_schema(ast_document)
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
my_user = Field(sdl_schema.get_type("User"))
|
||||||
|
|
||||||
|
schema = Schema(query=Query)
|
||||||
|
assert str(schema) == dedent(
|
||||||
|
"""\
|
||||||
|
type Query {
|
||||||
|
myUser: User
|
||||||
|
}
|
||||||
|
|
||||||
|
type User {
|
||||||
|
name: String!
|
||||||
|
pets: [Pet!]!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pet {
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user