How to use the tartiflette.types.field.GraphQLField function in tartiflette

To help you get started, we’ve selected a few tartiflette examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tartiflette / tartiflette / tests / unit / types / test_object.py View on Github external
def test_graphql_object_init(mocked_resolver_factory):
    obj = GraphQLObjectType(
        name="Name",
        fields=OrderedDict(
            [
                ("test", GraphQLField(name="arg", gql_type="Int")),
                ("another", GraphQLField(name="arg", gql_type="String")),
            ]
        ),
        interfaces=["First", "Second"],
        description="description",
    )

    assert obj.name == "Name"
    assert obj.find_field("test") == GraphQLField(name="arg", gql_type="Int")
    assert obj.find_field("another") == GraphQLField(
        name="arg", gql_type="String"
    )
    assert obj.interfaces_names == ["First", "Second"]
    assert obj.description == "description"
github tartiflette / tartiflette / tests / unit / types / test_interface.py View on Github external
def test_graphql_interface_init():
    interface = GraphQLInterfaceType(name="Name",
                                     fields=OrderedDict([
                                          ("test", GraphQLField(name="arg", gql_type="Int")),
                                          ("another", GraphQLField(name="arg", gql_type="String")),
                                      ]),
                                      description="description")

    assert interface.name == "Name"
    assert interface.fields == OrderedDict([
        ("test", GraphQLField(name="arg", gql_type="Int")),
        ("another", GraphQLField(name="arg", gql_type="String")),
    ])
    assert interface.description == "description"
github tartiflette / tartiflette / tests / unit / types / test_field.py View on Github external
def test_graphql_field_init():
    field = GraphQLField(
        name="Name",
        gql_type="Test",
        arguments=OrderedDict([("test", 42), ("another", 24)]),
        description="description",
    )

    assert field.name == "Name"
    assert field.gql_type == "Test"
    assert field.arguments == OrderedDict([("test", 42), ("another", 24)])
    assert field.resolver._directivated_func is default_resolver
    assert field.description == "description"
github tartiflette / tartiflette / tests / unit / sdl / test_build_graphql_schema_from_sdl.py View on Github external
expected_schema.add_definition(
        GraphQLUnionType(name="Group", gql_types=["Foo", "Bar", "Baz"])
    )
    expected_schema.add_definition(
        GraphQLInterfaceType(
            name="Something",
            fields=OrderedDict(
                oneField=GraphQLField(
                    name="oneField", gql_type=GraphQLList(gql_type="Int")
                ),
                anotherField=GraphQLField(
                    name="anotherField",
                    gql_type=GraphQLList(gql_type="String"),
                ),
                aLastOne=GraphQLField(
                    name="aLastOne",
                    gql_type=GraphQLNonNull(
                        gql_type=GraphQLList(
                            gql_type=GraphQLList(
                                gql_type=GraphQLNonNull(gql_type="Date")
                            )
                        )
                    ),
                ),
            ),
        )
    )
    expected_schema.add_definition(
        GraphQLInputObjectType(
            name="UserInfo",
            fields=OrderedDict(
github tartiflette / tartiflette / tests / unit / sdl / test_build_graphql_schema_from_sdl.py View on Github external
name="graphQLFan",
                            gql_type=GraphQLNonNull(gql_type="Boolean"),
                        ),
                    ),
                ]
            ),
        )
    )
    expected_schema.add_definition(
        GraphQLObjectType(
            name="Test",
            fields=OrderedDict(
                [
                    (
                        "field",
                        GraphQLField(
                            name="field",
                            gql_type=GraphQLNonNull(gql_type="String"),
                            arguments=OrderedDict(
                                input=GraphQLArgument(
                                    name="input", gql_type="InputObject"
                                )
                            ),
                        ),
                    ),
                    (
                        "anotherField",
                        GraphQLField(
                            name="anotherField",
                            gql_type=GraphQLList(gql_type="Int"),
                        ),
                    ),
github tartiflette / tartiflette / tests / unit / types / test_interface.py View on Github external
def test_graphql_interface_repr():
    interface = GraphQLInterfaceType(name="Name",
                                          fields=OrderedDict([
                                              ("test",
                                               GraphQLField(name="arg",
                                                               gql_type="Int")),
                                              ("another",
                                               GraphQLField(name="arg",
                                                               gql_type="String")),
                                          ]),
                                          description="description",)

    assert interface.__repr__() == "GraphQLInterfaceType(name='Name', " \
                                      "fields=OrderedDict([" \
                                      "('test', GraphQLField(name='arg', " \
                                   "gql_type='Int', arguments=OrderedDict(), " \
                                   "resolver=None, description=None, " \
                                   "directives=None)), " \
                                      "('another', GraphQLField(name='arg', " \
                                   "gql_type='String', arguments=OrderedDict(), " \
                                   "resolver=None, description=None, " \
github tartiflette / tartiflette / tests / unit / sdl / transformer / test_schema_transformer.py View on Github external
                                            GraphQLField,
                                            name="birthDate",
                                            gql_type="Date",
                                            arguments=OrderedDict(
                                                [
                                                    (
                                                        "input",
                                                        call_with_mocked_resolver_factory(
                                                            GraphQLArgument,
                                                            name="input",
                                                            gql_type="Date",
                                                            default_value="2018",
                                                        ),
                                                    )
                                                ]
                                            ),
                                        ),
github tartiflette / tartiflette / tests / unit / types / test_field.py View on Github external
def test_graphql_argument_eq(mocked_resolver_factory):
    field = GraphQLField(
        name="Name",
        gql_type="Test",
        arguments=OrderedDict([("test", 42), ("another", 24)]),
        description="description",
    )

    ## Same
    assert field == field
    assert field == GraphQLField(
        name="Name",
        gql_type="Test",
        arguments=OrderedDict([("test", 42), ("another", 24)]),
        description="description",
    )
    # Currently we ignore the description in comparing
    assert field == GraphQLField(
        name="Name",
        gql_type="Test",
        arguments=OrderedDict([("test", 42), ("another", 24)]),
    )

    ## Different
    assert field != GraphQLField(
        name="Name",
        gql_type="Test",
github tartiflette / tartiflette / tartiflette / schema / introspection.py View on Github external
:param ctx: context passed to the query execution
    :param info: information related to the execution and the resolved field
    :type parent: Optional[Any]
    :type args: Dict[str, Any]
    :type ctx: Optional[Any]
    :type info: ResolveInfo
    :return: the computed field value
    :rtype: Any
    """
    # pylint: disable=unused-argument
    info.is_introspection = True
    return info.schema


SCHEMA_ROOT_FIELD_DEFINITION = partial(
    GraphQLField,
    name="__schema",
    description="Access the current type schema of this server.",
    arguments=None,
    resolver=__schema_resolver,
)


async def __type_resolver(
    parent: Optional[Any],
    args: Dict[str, Any],
    ctx: Optional[Any],
    info: "ResolveInfo",
) -> "GraphQLType":
    """
    Callable to use to resolve the `__type` field.
    :param parent: default root value or field parent value
github tartiflette / tartiflette / tartiflette / schema / transformer.py View on Github external
def parse_field_definition(
    field_definition_node: "FieldDefinitionNode", schema: "GraphQLSchema"
) -> Optional["GraphQLField"]:
    """
    Computes an AST field definition node into a GraphQLField instance.
    :param field_definition_node: AST field definition node to treat
    :param schema: the GraphQLSchema instance linked to the engine
    :type field_definition_node: FieldDefinitionNode
    :type schema: GraphQLSchema
    :return: the GraphQLField instance
    :rtype: Optional[GraphQLField]
    """
    if not field_definition_node:
        return None

    return GraphQLField(
        name=parse_name(field_definition_node.name, schema),
        description=parse_name(field_definition_node.description, schema),
        gql_type=parse_type(field_definition_node.type, schema),
        arguments=parse_arguments_definition(
            field_definition_node.arguments, schema
        ),
        directives=field_definition_node.directives,
    )