예제 #1
0
def test_prints_string_field_with_multiple_args_last_is_default():
    output = print_single_field_schema(
        GraphQLField(
            type=GraphQLString,
            args=OrderedDict(
                [
                    ("argOne", GraphQLArgument(GraphQLInt)),
                    ("argTwo", GraphQLArgument(GraphQLString)),
                    ("argThree", GraphQLArgument(GraphQLBoolean, default_value=False)),
                ]
            ),
        )
    )

    assert (
        output
        == """
schema {
  query: Root
}

type Root {
  singleField(argOne: Int, argTwo: String, argThree: Boolean = false): String
}
"""
    )
예제 #2
0
def test_prints_string_field_with_multiple_args():
    output = print_single_field_schema(
        GraphQLField(
            type=GraphQLString,
            args=OrderedDict(
                [
                    ("argOne", GraphQLArgument(GraphQLInt)),
                    ("argTwo", GraphQLArgument(GraphQLString)),
                ]
            ),
        )
    )

    assert (
        output
        == """
schema {
  query: Root
}

type Root {
  singleField(argOne: Int, argTwo: String): String
}
"""
    )
예제 #3
0
def test_prints_string_field_with_multiple_args():
    output = print_single_field_schema(
        GraphQLField(type=GraphQLString,
                     args=OrderedDict([('argOne', GraphQLArgument(GraphQLInt)),
                                       ('argTwo',
                                        GraphQLArgument(GraphQLString))])))

    assert output == '''
예제 #4
0
def test_prints_string_field_with_multiple_args_last_is_default():
    output = print_single_field_schema(
        GraphQLField(type=GraphQLString,
                     args=OrderedDict([
                         ('argOne', GraphQLArgument(GraphQLInt)),
                         ('argTwo', GraphQLArgument(GraphQLString)),
                         ('argThree',
                          GraphQLArgument(GraphQLBoolean, default_value=False))
                     ])))

    assert output == '''
예제 #5
0
def test_prints_input_type():
    InputType = GraphQLInputObjectType(
        name="InputType", fields={"int": GraphQLInputObjectField(GraphQLInt)})

    Root = GraphQLObjectType(
        name="Root",
        fields={
            "str":
            GraphQLField(GraphQLString,
                         args={"argOne": GraphQLArgument(InputType)})
        },
    )

    Schema = GraphQLSchema(Root)
    output = print_for_test(Schema)

    assert (output == """
schema {
  query: Root
}

input InputType {
  int: Int
}

type Root {
  str(argOne: InputType): String
}
""")
예제 #6
0
 def get_args():
     return {
         'to': GraphQLArgument(
             type=GraphQLNonNull(GraphQLString),
             description='Value to default to',
         ),
     }
예제 #7
0
 def _get_entities_field(self, entity_type: GraphQLUnionType) -> GraphQLField:
     return GraphQLField(
         GraphQLNonNull(GraphQLList(entity_type)),
         args={
             "representations": GraphQLArgument(
                 GraphQLNonNull(GraphQLList(GraphQLNonNull(self.Any)))
             )
         },
         resolve=self.entities_resolver,
     )
예제 #8
0
def test_prints_string_field_with_int_arg():
    output = print_single_field_schema(
        GraphQLField(type=GraphQLString,
                     args={"argOne": GraphQLArgument(GraphQLInt)}))
    assert (output == """
schema {
  query: Root
}

type Root {
  singleField(argOne: Int): String
}
""")
def test_prints_string_field_with_int_arg_with_default():
    output = print_single_field_schema(
        GraphQLField(
            type_=GraphQLString,
            args={"argOne": GraphQLArgument(GraphQLInt, default_value=2)},
        ))
    assert (output == """
schema {
  query: Root
}

type Root {
  singleField(argOne: Int = 2): String
}
""")
예제 #10
0
def test_prints_input_type():
    InputType = GraphQLInputObjectType(
        name='InputType', fields={'int': GraphQLInputObjectField(GraphQLInt)})

    Root = GraphQLObjectType(
        name='Root',
        fields={
            'str':
            GraphQLField(GraphQLString,
                         args={'argOne': GraphQLArgument(InputType)})
        })

    Schema = GraphQLSchema(Root)
    output = print_for_test(Schema)

    assert output == '''
예제 #11
0
def test_prints_string_field_with_non_null_int_arg():
    output = print_single_field_schema(
        GraphQLField(
            type=GraphQLString,
            args={'argOne': GraphQLArgument(GraphQLNonNull(GraphQLInt))}))
    assert output == '''
예제 #12
0
def test_prints_string_field_with_int_arg_with_default():
    output = print_single_field_schema(
        GraphQLField(
            type=GraphQLString,
            args={'argOne': GraphQLArgument(GraphQLInt, default_value=2)}))
    assert output == '''
예제 #13
0
QueryRootType = GraphQLObjectType(
    name='QueryRoot',
    fields={
        'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
        'context': GraphQLField(
            type=GraphQLNonNull(GraphQLString),
            resolver=lambda self, info, **kwargs: info.context),

        'test': GraphQLField(
            type=GraphQLNonNull(GraphQLString),
            resolver=lambda self, info: 'Hello World'
        ),
        'test_args': GraphQLField(
            type=GraphQLNonNull(GraphQLString),
            args={'name': GraphQLArgument(GraphQLString)},
            resolver=lambda self, info, **kwargs: 'Hello {}'.format(kwargs.get("name"))
        ),
        'test_def_args': GraphQLField(
            type=GraphQLString,
            args={'name': GraphQLArgument(GraphQLString),},
            resolver=lambda self, info, name="World": 'Hello {}'.format(name)
        )
    }
)

MutationRootType = GraphQLObjectType(
    name='MutationRoot',
    fields={
        'writeTest': GraphQLField(
            type=QueryRootType,
예제 #14
0
def resolve_raises(*_):
    raise Exception("Throws!")


QueryRootType = GraphQLObjectType(
    name='QueryRoot',
    fields={
        'thrower':
        GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
        'request':
        GraphQLField(
            GraphQLNonNull(GraphQLString),
            resolver=lambda obj, args, context, info: context.args.get('q')),
        'test':
        GraphQLField(type=GraphQLString,
                     args={'who': GraphQLArgument(GraphQLString)},
                     resolver=lambda obj, args, context, info: 'Hello %s' %
                     (args.get('who') or 'World'))
    })

MutationRootType = GraphQLObjectType(name='MutationRoot',
                                     fields={
                                         'writeTest':
                                         GraphQLField(
                                             type=QueryRootType,
                                             resolver=lambda *_: QueryRootType)
                                     })

Schema = GraphQLSchema(QueryRootType, MutationRootType)
        "context": GraphQLField(
            GraphQLObjectType(
                name="context",
                fields={
                    "session": GraphQLField(GraphQLString),
                    "request": GraphQLField(
                        GraphQLNonNull(GraphQLString),
                        resolve=lambda obj, info: info.context["request"],
                    ),
                },
            ),
            resolve=lambda obj, info: info.context,
        ),
        "test": GraphQLField(
            type_=GraphQLString,
            args={"who": GraphQLArgument(GraphQLString)},
            resolve=lambda obj, info, who="World": "Hello %s" % who,
        ),
        "characters": GraphQLField(
            type_=GraphQLString,
            args={"who": GraphQLArgument(GraphQLString)},
            resolve=lambda obj, info, who="World": "Hello %s" % who,
        ),
    },
)

MutationRootType = GraphQLObjectType(
    name="MutationRoot",
    description="Root mutations",
    fields={
        "writeTest": GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType),
예제 #16
0
def executeSQL(query, *args, **kwargs):
    con, conn = connection()
    con.execute(query, *args, **kwargs)
    result = con.fetchone()
    con.close()
    conn.close()
    gc.collect()
    return result


QueryRootType = GraphQLObjectType(
    name='QueryRoot',
    fields={
        'getUser':
        GraphQLField(type=GraphQLString,
                     args={'ident': GraphQLArgument(GraphQLInt)},
                     resolver=lambda obj, info, ident: executeSQL(
                         "SELECT * FROM user WHERE iduser = %s",
                         escape_string(str(ident)))),
        'getNoteByParentId':
        GraphQLField(type=GraphQLString,
                     args={'parent_id': GraphQLArgument(GraphQLInt)},
                     resolver=lambda obj, info, parent_id: executeSQL(
                         "SELECT title FROM note_view WHERE parent_id = %s",
                         escape_string(str(parent_id)))),
        'getNotegroupById':
        GraphQLField(type=GraphQLString,
                     args={
                         'notegroup_id': GraphQLArgument(GraphQLInt),
                         'access_token': GraphQLArgument(GraphQLString)
                     },
예제 #17
0
def resolve_raises(*_):
    raise Exception("Throws!")


QueryRootType = GraphQLObjectType(
    name='QueryRoot',
    fields={
        'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
        'request': GraphQLField(GraphQLNonNull(GraphQLString),
                                resolver=lambda obj, info: info.context.params.get('q')),
        'context': GraphQLField(GraphQLNonNull(GraphQLString),
                                resolver=lambda obj, info: info.context),
        'test': GraphQLField(
            type=GraphQLString,
            args={
                'who': GraphQLArgument(GraphQLString)
            },
            resolver=lambda obj, info, who='World': 'Hello %s' % who
        )
    }
)

MutationRootType = GraphQLObjectType(
    name='MutationRoot',
    fields={
        'writeTest': GraphQLField(
            type=QueryRootType,
            resolver=lambda *_: QueryRootType
        )
    }
)
예제 #18
0
                fields={
                    "session":
                    GraphQLField(GraphQLString),
                    "request":
                    GraphQLField(
                        GraphQLNonNull(GraphQLString),
                        resolve=lambda obj, info: info.context["request"],
                    ),
                },
            ),
            resolve=lambda obj, info: info.context,
        ),
        "test":
        GraphQLField(
            type_=GraphQLString,
            args={"who": GraphQLArgument(GraphQLString)},
            resolve=lambda obj, info, who=None: "Hello %s" % (who or "World"),
        ),
    },
)

MutationRootType = GraphQLObjectType(
    name="MutationRoot",
    fields={
        "writeTest":
        GraphQLField(type_=QueryRootType, resolve=lambda *_: QueryRootType)
    },
)

Schema = GraphQLSchema(QueryRootType, MutationRootType)
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
from graphql.type.scalars import GraphQLString, GraphQLBoolean
from graphql.type.schema import GraphQLSchema

Query = GraphQLObjectType(
    name='Query',
    fields={
        'testString':
        GraphQLField(
            GraphQLNonNull(GraphQLString),
            resolver=lambda root, args, context, info: 'string returned')
    })

Subscription = GraphQLObjectType(
    name='Subscription',
    fields={
        'test_subscription':
        GraphQLField(type=GraphQLNonNull(GraphQLString),
                     resolver=lambda root, args, context, info: root),
        'test_filter_sub':
        GraphQLField(type=GraphQLNonNull(GraphQLString),
                     args={'filter_bool': GraphQLArgument(GraphQLBoolean)},
                     resolver=lambda root, args, context, info: 'SUCCESS'),
    })

Schema = GraphQLSchema(Query, subscription=Subscription)