def test_builds_a_schema_with_custom_directives(): schema = GraphQLSchema(query=GraphQLObjectType( name='Simple', description='This is a simple type', fields={ 'string': GraphQLField(type=GraphQLString, description='This is a string field') }, ), directives=[ GraphQLDirective( name='customDirective', description='This is a custom directive', locations=['FIELD']) ]) _test_schema(schema)
def test_builds_a_schema_with_custom_directives(): schema = GraphQLSchema( query=GraphQLObjectType( name="Simple", description="This is a simple type", fields={ "string": GraphQLField(type=GraphQLString, description="This is a string field") }, ), directives=[ GraphQLDirective( name="customDirective", description="This is a custom directive", locations=["FIELD"], ) ], ) _test_schema(schema)
"complicatedArgs": GraphQLField(ComplicatedArgs), "invalidArg": GraphQLField(GraphQLString, args={"arg": GraphQLArgument(InvalidScalar)}), "anyArg": GraphQLField(GraphQLString, args={"arg": GraphQLArgument(AnyScalar)}), }, ) test_schema = GraphQLSchema( query=QueryRoot, directives=[ GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDirective(name="onQuery", locations=[DirectiveLocation.QUERY]), GraphQLDirective(name="onMutation", locations=[DirectiveLocation.MUTATION]), GraphQLDirective(name="onSubscription", locations=[DirectiveLocation.SUBSCRIPTION]), GraphQLDirective(name="onField", locations=[DirectiveLocation.FIELD]), GraphQLDirective( name="onFragmentDefinition", locations=[DirectiveLocation.FRAGMENT_DEFINITION], ), GraphQLDirective(name="onFragmentSpread", locations=[DirectiveLocation.FRAGMENT_SPREAD]), GraphQLDirective(name="onInlineFragment", locations=[DirectiveLocation.INLINE_FRAGMENT]), GraphQLDirective( name="onVariableDefinition",
QueryRoot = GraphQLObjectType( 'QueryRoot', { 'human': GraphQLField(Human, { 'id': GraphQLArgument(GraphQLID), }), 'dog': GraphQLField(Dog), 'pet': GraphQLField(Pet), 'alien': GraphQLField(Alien), 'catOrDog': GraphQLField(CatOrDog), 'humanOrAlien': GraphQLField(HumanOrAlien), 'complicatedArgs': GraphQLField(ComplicatedArgs), }) test_schema = GraphQLSchema(query=QueryRoot, directives=[ GraphQLDirective(name='operationOnly', locations=['QUERY']), GraphQLIncludeDirective, GraphQLSkipDirective ], types=[Cat, Dog, Human, Alien]) def expect_valid(schema, rules, query): errors = validate(schema, parse(query), rules) assert errors == [], 'Should validate' def sort_lists(value): if isinstance(value, dict): new_mapping = [] for k, v in value.items(): new_mapping.append((k, sort_lists(v)))
"human": GraphQLField(Human, {"id": GraphQLArgument(GraphQLID)}), "dog": GraphQLField(Dog), "pet": GraphQLField(Pet), "alien": GraphQLField(Alien), "catOrDog": GraphQLField(CatOrDog), "humanOrAlien": GraphQLField(HumanOrAlien), "complicatedArgs": GraphQLField(ComplicatedArgs), }, ) test_schema = GraphQLSchema( query=QueryRoot, directives=[ GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDirective(name="onQuery", locations=[DirectiveLocation.QUERY]), GraphQLDirective(name="onMutation", locations=[DirectiveLocation.MUTATION]), GraphQLDirective(name="onSubscription", locations=[DirectiveLocation.SUBSCRIPTION]), GraphQLDirective(name="onField", locations=[DirectiveLocation.FIELD]), GraphQLDirective( name="onFragmentDefinition", locations=[DirectiveLocation.FRAGMENT_DEFINITION], ), GraphQLDirective(name="onFragmentSpread", locations=[DirectiveLocation.FRAGMENT_SPREAD]), GraphQLDirective(name="onInlineFragment", locations=[DirectiveLocation.INLINE_FRAGMENT]), GraphQLDirective(name="OnSchema", locations=[DirectiveLocation.SCHEMA]),
from unicodedata import name from graphql import GraphQLArgument, GraphQLNonNull, GraphQLString from graphql.type.directives import GraphQLDirective, DirectiveLocation, GraphQLDeprecatedDirective, GraphQLSkipDirective ShowNetworkDirective = GraphQLDirective( name="show_network", locations=[ DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT, ], args={ "style": GraphQLArgument( GraphQLNonNull(GraphQLString) ) }, description="Displays the network associated with an IP Address (CIDR or Net)." ) DeprecatedDirective = GraphQLDeprecatedDirective SkipDirective = GraphQLSkipDirective