mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 01:26:49 +03:00
Add SDL example
This commit is contained in:
parent
2fbe0a67af
commit
730688916e
|
@ -1,6 +1,7 @@
|
|||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
from graphql import parse, build_ast_schema
|
||||
from graphql.type import (
|
||||
GraphQLArgument,
|
||||
GraphQLEnumType,
|
||||
|
@ -392,3 +393,39 @@ def test_graphql_type_union():
|
|||
)
|
||||
assert not results.errors
|
||||
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