Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_graphql_query_string_causes_syntax_error():
with pytest.raises(GraphQLSyntaxError):
gql(
"""
query TestQuery {
def test_valid_graphql_query_string_is_returned_unchanged():
query = """
query TestQuery {
auth
users {
id
username
}
}
"""
result = gql(query)
assert query == result
def test_invalid_graphql_schema_string_causes_syntax_error():
with pytest.raises(GraphQLSyntaxError):
gql(
"""
type User {
def test_valid_graphql_schema_string_is_returned_unchanged():
sdl = """
type User {
username: String!
}
"""
result = gql(sdl)
assert sdl == result
"""Example 01: The Basics.
Run with::
$ uvicorn example:app
"""
from ariadne import MutationType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
# This is our schema
type_defs = gql(
"""
type Query {
hello: String!
}
type Mutation {
add(a: Int!, b: Int!): Int!
}
"""
)
query = QueryType() # our Query type
mutation = MutationType() # our Mutation type
@query.field("hello") # Query.hello
import asyncio
from ariadne import gql, ResolverMap
from ariadne.executable_schema import make_executable_schema
from channels.routing import ProtocolTypeRouter, URLRouter
from django.conf.urls import url
from graphql.pyutils import EventEmitter, EventEmitterAsyncIterator
from graphql.subscription import subscribe
from .database import db, init_database, Note
from .graphql import GraphQLHTTPConsumer, GraphQLWebsocketConsumer
from .subscription import SubscriptionAwareResolverMap
SCHEMA = gql(
"""
type Note {
id: ID!
title: String
body: String
}
type Query {
hello: String!
notes: [Note!]!
notesContaining(query: String!): [Note!]!
}
type Mutation {
createNote(title: String!, body: String!): Note!
sendMessage(message: String!): Boolean!
"""Example 02: Object Types.
Run with::
$ uvicorn example:app
"""
from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
# This is our schema
type_defs = gql(
"""
type Book {
title: String!
year: Int!
age: Int!
}
type Query {
books: [Book!]!
}
"""
)
query = QueryType() # our Query type
"""Example 02: Object Types.
Run with::
$ uvicorn example:app
"""
from ariadne import ObjectType, QueryType, gql, make_executable_schema
from ariadne.asgi import GraphQL
# This is our schema
type_defs = gql(
"""
type Book {
title: String!
year: Int!
}
type Query {
books: [Book!]!
}
"""
)
query = QueryType() # our Query type
@query.field("books") # Query.books
from ariadne import gql, make_executable_schema
# This is our schema
type_defs = gql(
"""
type Query {
hello: String!
}
"""
)
# Create an executable GraphQL schema
schema = make_executable_schema(type_defs, [])
from ariadne import gql, make_executable_schema
# This is our schema
type_defs = gql(
"""
type Query {
hello: String!
}
"""
)
# Create an executable GraphQL schema
schema = make_executable_schema(type_defs, [])