Debian Codegraph @

docs/intro.rst

raw
1 Introduction
2 ============
3
4 `GraphQL-core-3`_ is a Python port of `GraphQL.js`_,
5 the JavaScript reference implementation for GraphQL_,
6 a query language for APIs created by Facebook.
7
8 `GraphQL`_ consists of three parts:
9
10 * A type system that you define
11 * A query language that you use to query the API
12 * An execution and validation engine
13
14 The reference implementation closely follows the `Specification for GraphQL`_
15 which consists of the following sections:
16
17 * Language_
18 * `Type System`_
19 * Introspection_
20 * Validation_
21 * Execution_
22 * Response_
23
24 This division into subsections is reflected in the :ref:`sub-packages` of
25 GraphQL-core 3. Each of these sub-packages implements the aspects specified in
26 one of the sections of the specification.
27
28
29 Getting started
30 ---------------
31
32 You can install GraphQL-core 3 using pip_::
33
34 pip install graphql-core
35
36 You can also install GraphQL-core 3 with poetry_, if you prefer that::
37
38 poetry install
39
40 Now you can start using GraphQL-core 3 by importing from the top-level
41 :mod:`graphql` package. Nearly everything defined in the sub-packages
42 can also be imported directly from the top-level package.
43
44 .. currentmodule:: graphql
45
46 For instance, using the types defined in the :mod:`graphql.type` package,
47 you can define a GraphQL schema, like this simple one::
48
49 from graphql import (
50 GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString)
51
52 schema = GraphQLSchema(
53 query=GraphQLObjectType(
54 name='RootQueryType',
55 fields={
56 'hello': GraphQLField(
57 GraphQLString,
58 resolve=lambda obj, info: 'world')
59 }))
60
61 The :mod:`graphql.execution` package implements the mechanism for executing
62 GraphQL queries. The top-level :func:`graphql` and :func:`graphql_sync`
63 functions also parse and validate queries using the :mod:`graphql.language`
64 and :mod:`graphql.validation` modules.
65
66 So to validate and execute a query against our simple schema, you can do::
67
68 from graphql import graphql_sync
69
70 query = '{ hello }'
71
72 print(graphql_sync(schema, query))
73
74 This will yield the following output::
75
76 ExecutionResult(data={'hello': 'world'}, errors=None)
77
78
79 Reporting Issues and Contributing
80 ---------------------------------
81
82 Please visit the `GitHub repository of GraphQL-core 3`_ if you're interested
83 in the current development or want to report issues or send pull requests.
84
85 .. _GraphQL: https://graphql.org/
86 .. _GraphQL.js: https://github.com/graphql/graphql-js
87 .. _GraphQL-core-3: https://github.com/graphql-python/graphql-core
88 .. _GitHub repository of GraphQL-core 3: https://github.com/graphql-python/graphql-core
89 .. _Specification for GraphQL: https://facebook.github.io/graphql/
90 .. _Language: https://facebook.github.io/graphql/draft/#sec-Language
91 .. _Type System: https://facebook.github.io/graphql/draft/#sec-Type-System
92 .. _Introspection: https://facebook.github.io/graphql/draft/#sec-Introspection
93 .. _Validation: https://facebook.github.io/graphql/draft/#sec-Validation
94 .. _Execution: https://facebook.github.io/graphql/draft/#sec-Execution
95 .. _Response: https://facebook.github.io/graphql/draft/#sec-Response
96 .. _pip: https://pip.pypa.io/
97 .. _poetry: https://github.com/python-poetry/poetry