Skip to content

Commit

Permalink
Updated imports and README with working examples
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed May 4, 2016
1 parent bff187a commit af57ecf
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 94 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ schema = GraphQLSchema(
fields={
'hello': GraphQLField(
type= GraphQLString,
resolve=lambda *_: 'world'
resolver=lambda *_: 'world'
)
}
)
Expand All @@ -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
Expand All @@ -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
Expand Down
168 changes: 86 additions & 82 deletions graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = (
Expand All @@ -166,6 +168,8 @@
'GraphQLInterfaceType',
'GraphQLList',
'GraphQLNonNull',
'GraphQLField',
'GraphQLArgument',
'GraphQLObjectType',
'GraphQLScalarType',
'GraphQLSchema',
Expand Down

0 comments on commit af57ecf

Please sign in to comment.