zapier/graphql-core

Name: graphql-core

Owner: Zapier

Description: GraphQL base implementation for Python

Created: 2018-04-20 20:52:55.0

Updated: 2018-04-20 21:02:17.0

Pushed: 2018-04-20 21:02:15.0

Homepage:

Size: 1288

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

GraphQL-core

GraphQL for Python.

This library is a port of graphql-js to Python and currently is up-to-date with release 0.6.0.

PyPI version Build Status Coverage Status Public Slack Discussion

See more complete documentation at http://graphql.org/ and http://graphql.org/docs/api-reference-graphql/.

For questions, ask Stack Overflow.

Getting Started

An overview of the GraphQL language is available in the README for the Specification for GraphQL.

The overview describes a simple set of GraphQL examples that exist as tests in this repository. A good way to get started is to walk through that README and the corresponding tests in parallel.

Using graphql-core

Install from pip:

install graphql-core

GraphQL.js provides two important capabilities: building a type schema, and serving queries against that type schema.

First, build a GraphQL type schema which maps to your code base.

 graphql import (
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLField,
GraphQLString


ma = GraphQLSchema(
ery= GraphQLObjectType(
name='RootQueryType',
fields={
  'hello': GraphQLField(
    type= GraphQLString,
    resolver=lambda *_: 'world'
  )
}


This defines a simple schema with one type and one field, that resolves to a fixed value. The resolve function can return a value, a promise, or an array of promises. A more complex example is included in the top level tests directory.

Then, serve the result of a query against that type schema.

y = '{ hello }'

lt = graphql(schema, query)

ints
hello': 'world'} (as OrderedDict)

t result.data

This runs a query fetching the one field defined. The graphql function will first ensure the query is syntactically and semantically valid before executing it, reporting errors otherwise.

y = '{ boyhowdy }'

lt = graphql(schema, query)

ints
raphQLError('Cannot query field "boyhowdy" on type "RootQueryType".',)]

t result.errors
Executors

The graphql query is executed, by default, synchronously (using SyncExecutor). However the following executors are available if we want to resolve our fields in parallel:

Usage

You can specify the executor to use via the executor keyword argument in the grapqhl.execution.execute function.

 graphql.execution.execute import execute

ute(schema, ast, executor=SyncExecutor())
Main Contributors
License

MIT License


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.