From af57ecfd0078ce1af4eb203a0d5088d6055668ef Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 3 May 2016 22:56:39 -0700 Subject: [PATCH] Updated imports and README with working examples --- README.md | 19 ++--- graphql/__init__.py | 168 +++++++++++++++++++++++--------------------- 2 files changed, 93 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 2f51133f..fe72d57e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ schema = GraphQLSchema( fields={ 'hello': GraphQLField( type= GraphQLString, - resolve=lambda *_: 'world' + resolver=lambda *_: 'world' ) } ) @@ -72,10 +72,9 @@ query = '{ hello }' result = graphql(schema, query) # Prints -# { -# "data": { "hello": "world" } -# } -print result +# {'hello': 'world'} (as OrderedDict) + +print result.data ``` This runs a query fetching the one field defined. The `graphql` function will @@ -88,13 +87,9 @@ query = '{ boyhowdy }' result = graphql(schema, query) # Prints -# { -# "errors": [ -# { "message": "Cannot query field boyhowdy on RootQueryType", -# "locations": [ { "line": 1, "column": 3 } ] } -# ] -# } -print result +# [GraphQLError('Cannot query field "boyhowdy" on type "RootQueryType".',)] + +print result.errors ``` ### Executors diff --git a/graphql/__init__.py b/graphql/__init__.py index 65caaf12..050bced0 100644 --- a/graphql/__init__.py +++ b/graphql/__init__.py @@ -25,134 +25,136 @@ # The primary entry point into fulfilling a GraphQL request. from .graphql import ( - graphql + graphql ) # Create and operate on GraphQL type definitions and schema. from .type import ( # no import order - GraphQLSchema, - - # Definitions - GraphQLScalarType, - GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, - GraphQLEnumType, - GraphQLInputObjectType, - GraphQLList, - GraphQLNonNull, - - # Scalars - GraphQLInt, - GraphQLFloat, - GraphQLString, - GraphQLBoolean, - GraphQLID, - - # Predicates - is_type, - is_input_type, - is_output_type, - is_leaf_type, - is_composite_type, - is_abstract_type, - - # Un-modifiers - get_nullable_type, - get_named_type, + GraphQLSchema, + + # Definitions + GraphQLScalarType, + GraphQLObjectType, + GraphQLInterfaceType, + GraphQLUnionType, + GraphQLEnumType, + GraphQLInputObjectType, + GraphQLList, + GraphQLNonNull, + GraphQLField, + GraphQLArgument, + + # Scalars + GraphQLInt, + GraphQLFloat, + GraphQLString, + GraphQLBoolean, + GraphQLID, + + # Predicates + is_type, + is_input_type, + is_output_type, + is_leaf_type, + is_composite_type, + is_abstract_type, + + # Un-modifiers + get_nullable_type, + get_named_type, ) # Parse and operate on GraphQL language source files. from .language.base import ( # no import order - Source, - get_location, + Source, + get_location, - # Parse - parse, - parse_value, + # Parse + parse, + parse_value, - # Print - print_ast, + # Print + print_ast, - # Visit - visit, - ParallelVisitor, - TypeInfoVisitor, - BREAK, + # Visit + visit, + ParallelVisitor, + TypeInfoVisitor, + BREAK, ) # Execute GraphQL queries. from .execution import ( # no import order - execute, + execute, ) # Validate GraphQL queries. from .validation import ( # no import order - validate, - specified_rules, + validate, + specified_rules, ) # Create and format GraphQL errors. from .error import ( - GraphQLError, - format_error, + GraphQLError, + format_error, ) # Utilities for operating on GraphQL type schema and parsed sources. from .utils.base import ( - # The GraphQL query recommended for a full schema introspection. - introspection_query, + # The GraphQL query recommended for a full schema introspection. + introspection_query, - # Gets the target Operation from a Document - get_operation_ast, + # Gets the target Operation from a Document + get_operation_ast, - # Build a GraphQLSchema from an introspection result. - build_client_schema, + # Build a GraphQLSchema from an introspection result. + build_client_schema, - # Build a GraphQLSchema from a parsed GraphQL Schema language AST. - build_ast_schema, + # Build a GraphQLSchema from a parsed GraphQL Schema language AST. + build_ast_schema, - # Extends an existing GraphQLSchema from a parsed GraphQL Schema - # language AST. - extend_schema, + # Extends an existing GraphQLSchema from a parsed GraphQL Schema + # language AST. + extend_schema, - # Print a GraphQLSchema to GraphQL Schema language. - print_schema, + # Print a GraphQLSchema to GraphQL Schema language. + print_schema, - # Create a GraphQLType from a GraphQL language AST. - type_from_ast, + # Create a GraphQLType from a GraphQL language AST. + type_from_ast, - # Create a JavaScript value from a GraphQL language AST. - value_from_ast, + # Create a JavaScript value from a GraphQL language AST. + value_from_ast, - # Create a GraphQL language AST from a JavaScript value. - ast_from_value, + # Create a GraphQL language AST from a JavaScript value. + ast_from_value, - # A helper to use within recursive-descent visitors which need to be aware of - # the GraphQL type system. - TypeInfo, + # A helper to use within recursive-descent visitors which need to be aware of + # the GraphQL type system. + TypeInfo, - # Determine if JavaScript values adhere to a GraphQL type. - is_valid_value, + # Determine if JavaScript values adhere to a GraphQL type. + is_valid_value, - # Determine if AST values adhere to a GraphQL type. - is_valid_literal_value, + # Determine if AST values adhere to a GraphQL type. + is_valid_literal_value, - # Concatenates multiple AST together. - concat_ast, + # Concatenates multiple AST together. + concat_ast, - # Comparators for types - is_equal_type, - is_type_sub_type_of, - do_types_overlap, + # Comparators for types + is_equal_type, + is_type_sub_type_of, + do_types_overlap, - # Asserts a string is a valid GraphQL name. - assert_valid_name, + # Asserts a string is a valid GraphQL name. + assert_valid_name, ) __all__ = ( @@ -166,6 +168,8 @@ 'GraphQLInterfaceType', 'GraphQLList', 'GraphQLNonNull', + 'GraphQLField', + 'GraphQLArgument', 'GraphQLObjectType', 'GraphQLScalarType', 'GraphQLSchema',