在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graphql-python/graphql-core-legacy开源软件地址(OpenSource Url):https://github.com/graphql-python/graphql-core-legacy开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):GraphQL-core 2The repository for the current version is available at github.com/graphql-python/graphql-core. This library is a port of GraphQL.js to Python and up-to-date with release 0.6.0. GraphQL-core 2 supports Python version 2.7, 3.5, 3.6, 3.7 and 3.8. GraphQL.js is the JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook. See also the GraphQL documentation at graphql.org and graphql.org/graphql-js/graphql/. For questions regarding GraphQL, ask Stack Overflow. Getting StartedAn 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 2Install from pip: pip install "graphql-core<3" GraphQL-core 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. from graphql import (
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLField,
GraphQLString
)
schema = GraphQLSchema(
query=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 Then, serve the result of a query against that type schema. query = '{ hello }'
result = graphql(schema, query)
# Prints
# {'hello': 'world'} (as OrderedDict)
print result.data This runs a query fetching the one field defined. The query = '{ boyhowdy }'
result = graphql(schema, query)
# Prints
# [GraphQLError('Cannot query field "boyhowdy" on type "RootQueryType".',)]
print result.errors ExecutorsThe graphql query is executed, by default, synchronously (using
UsageYou can specify the executor to use via the executor keyword argument in the from graphql import parse
from graphql.execution import execute
from graphql.execution.executors.sync import SyncExecutor
ast = parse('{ hello }')
result = execute(schema, ast, executor=SyncExecutor())
print result.data ContributingAfter cloning this repo, create a virtualenv and ensure dependencies are installed by running: virtualenv venv
source venv/bin/activate
pip install -e ".[test]" Well-written tests and maintaining good test coverage is important to this project. While developing, run new and existing tests with: pytest PATH/TO/MY/DIR/test_test.py # Single file
pytest PATH/TO/MY/DIR/ # All tests in directory Add the GraphQL-core 2 supports several versions of Python. To make sure that changes do not break compatibility
with any of those versions, we use tox If you wish to run against a specific version defined in the tox -e py36 Tox can only use whatever versions of python are installed on your system. When you create a pull request, Travis will also be running the same tests and report the results, so there is no need for potential contributors to try to install every single version of python on their own system ahead of time. We appreciate opening issues and pull requests to make GraphQL-core even more stable & useful! Main ContributorsLicense |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论