def rejects_a_directive_with_incorrectly_typed_ast_node(): with raises(TypeError) as exc_info: # noinspection PyTypeChecker GraphQLDirective("Foo", locations=[], ast_node=Node()) # type: ignore assert str(exc_info.value) == ( "Foo AST node must be a DirectiveDefinitionNode.")
def check_value_node(): assert not is_value_node(Node()) assert not is_value_node(DocumentNode()) assert is_value_node(ValueNode()) assert is_value_node(IntValueNode()) assert is_value_node(ObjectValueNode()) assert not is_value_node(TypeNode())
def does_not_accept_a_bad_ast_node(): with raises(TypeError) as exc_info: # noinspection PyTypeChecker GraphQLDirective('test', locations=[], ast_node=Node()) # type: ignore assert str(exc_info.value) == ( 'test AST node must be a DirectiveDefinitionNode.')
def formats_graphql_error(): source = Source( """ query { something }""" ) path: List[Union[int, str]] = ["one", 2] extensions = {"ext": None} error = GraphQLError( "test message", Node(), source, [14, 40], path, ValueError("original"), extensions=extensions, ) formatted = format_error(error) assert formatted == error.formatted assert formatted == { "message": "test message", "locations": [{"line": 2, "column": 14}, {"line": 3, "column": 20}], "path": path, "extensions": extensions, }
def check_selection_node(): assert not is_selection_node(Node()) assert not is_selection_node(DocumentNode()) assert is_selection_node(SelectionNode()) assert is_selection_node(FieldNode()) assert is_selection_node(InlineFragmentNode()) assert not is_selection_node(SelectionSetNode())
def formats_graphql_error(): path: List[Union[int, str]] = ["one", 2] extensions = {"ext": None} error = GraphQLError( "test message", Node(), Source(""" query { something } """), [16, 41], ["one", 2], ValueError("original"), extensions=extensions, ) assert error.formatted == { "message": "test message", "locations": [{ "line": 2, "column": 16 }, { "line": 3, "column": 17 }], "path": path, "extensions": extensions, }
def check_type_extension_node(): assert not is_type_extension_node(Node()) assert not is_type_extension_node(DocumentNode()) assert is_type_extension_node(TypeExtensionNode()) assert not is_type_extension_node(ScalarTypeDefinitionNode()) assert is_type_extension_node(ScalarTypeExtensionNode()) assert not is_type_extension_node(DefinitionNode()) assert not is_type_extension_node(TypeNode())
def check_type_system_extension_node(): assert not is_type_system_extension_node(Node()) assert not is_type_system_extension_node(DocumentNode()) assert is_type_system_extension_node(SchemaExtensionNode()) assert is_type_system_extension_node(TypeExtensionNode()) assert not is_type_system_extension_node(TypeSystemDefinitionNode()) assert not is_type_system_extension_node(DefinitionNode()) assert not is_type_system_extension_node(TypeNode())
def check_type_definition_node(): assert not is_type_definition_node(Node()) assert not is_type_definition_node(DocumentNode()) assert is_type_definition_node(TypeDefinitionNode()) assert is_type_definition_node(ScalarTypeDefinitionNode()) assert not is_type_definition_node(TypeSystemDefinitionNode()) assert not is_type_definition_node(DefinitionNode()) assert not is_type_definition_node(TypeNode())
def can_check_equality(): node = SampleTestNode(alpha=1, beta=2) node2 = SampleTestNode(alpha=1, beta=2) assert node2 == node node2 = SampleTestNode(alpha=1, beta=1) assert node2 != node node2 = Node(alpha=1, beta=2) assert node2 != node
def format_graphql_error(): source = Source(""" query { something }""") path = ['one', 2] extensions = {'ext': None} error = GraphQLError('test message', Node(), source, [14, 40], path, ValueError('original'), extensions=extensions) assert error == { 'message': 'test message', 'locations': [(2, 14), (3, 20)], 'path': path, 'extensions': extensions }
def format_graphql_error(): source = Source(""" query { something }""") path: List[Union[int, str]] = ["one", 2] extensions = {"ext": None} error = GraphQLError( "test message", Node(), source, [14, 40], path, ValueError("original"), extensions=extensions, ) assert error == { "message": "test message", "locations": [(2, 14), (3, 20)], "path": path, "extensions": extensions, }
def check_type_node(): assert not is_type_node(Node()) assert not is_type_node(DocumentNode()) assert not is_type_node(ValueNode()) assert is_type_node(TypeNode()) assert is_type_node(NonNullTypeNode())
def check_exectuable_definition_node(): assert not is_executable_definition_node(Node()) assert not is_executable_definition_node(DocumentNode()) assert not is_executable_definition_node(DefinitionNode()) assert is_executable_definition_node(ExecutableDefinitionNode()) assert not is_executable_definition_node(TypeSystemDefinitionNode())