How to use the gql.query_parser.ParsedObject function in gql

To help you get started, we’ve selected a few gql 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 graphql-python / gql-next / tests / test_query_parser.py View on Github external
fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Film',
                                parents=['FilmFields'],
                                fields=[
                                    ParsedField(name='id', type='str', nullable=False),
                                ]
                            )
                        ],
                    ),
                ]
            ),
            ParsedObject(
                name='FilmFields',
                fields=[
                    ParsedField(name='title', type='str', nullable=False),
                    ParsedField(name='director', type='str', nullable=False),
                ],
            )
        ]
    ))

    parsed_dict = asdict(parsed)

    assert bool(parsed)
    assert parsed_dict == expected, str(DeepDiff(parsed_dict, expected))
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
director
          }
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetFilm',
                type='query',
                children=[
                    ParsedObject(
                        name='GetFilmData',
                        fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Film',
                                fields=[
                                    ParsedField(name='title', type='str', nullable=False),
                                    ParsedField(name='director', type='str', nullable=False),
                                ]
                            )
                        ]
                    )
                ]
            )
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
ParsedObject(
                        name='GetPersonData',
                        fields=[
                            ParsedField(name='luke', type='Person', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Person',
                                parents=['CharacterFields'],
                                fields=[]
                            )
                        ],
                    ),
                ]
            ),
            ParsedObject(
                name='CharacterFields',
                fields=[
                    ParsedField(name='name', type='str', nullable=False),
                    ParsedField(name='home', type='Planet', nullable=False),
                ],
                children=[
                    ParsedObject(
                        name='Planet',
                        fields=[
                            ParsedField(name='name', type='str', nullable=False),
                        ]
                    )
                ]
            )
        ]
    ))
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
}
          }
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetFilm',
                type='query',
                children=[
                    ParsedObject(
                        name='GetFilmData',
                        fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Film',
                                fields=[
                                    ParsedField(name='title', type='str', nullable=False),
                                    ParsedField(name='director', type='str', nullable=False),
                                ]
                            )
                        ],
                    )
                ]
            )
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
ok
          }
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='CreateHero',
                type='mutation',
                children=[
                    ParsedObject(
                        name='CreateHeroData',
                        fields=[
                            ParsedField(name='createHero', type='CreateHeroPayload', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='CreateHeroPayload',
                                fields=[
                                    ParsedField(name='hero', type='Hero', nullable=True),
                                    ParsedField(name='ok', type='bool', nullable=True)
                                ],
                                children=[
                                    ParsedObject(
                                        name='Hero',
                                        fields=[
                                            ParsedField(name='name', type='str', nullable=False)
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
title
            director
        }
    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetFilm',
                type='query',
                children=[
                    ParsedObject(
                        name='GetFilmData',
                        fields=[
                            ParsedField(name='returnOfTheJedi', type='Film', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='Film',
                                parents=['FilmFields'],
                                fields=[
                                    ParsedField(name='id', type='str', nullable=False),
                                ]
                            )
                        ],
                    ),
                ]
            ),
github graphql-python / gql-next / tests / test_query_parser.py View on Github external
name
        }

    """

    parser = QueryParser(swapi_schema)
    parsed = parser.parse(query)

    expected = asdict(ParsedQuery(
        query=query,
        objects=[
            ParsedOperation(
                name='GetAllFilms',
                type='query',
                children=[
                    ParsedObject(
                        name='GetAllFilmsData',
                        fields=[
                            ParsedField(name='allFilms', type='FilmConnection', nullable=True),
                            ParsedField(name='allHeroes', type='HeroConnection', nullable=True)
                        ],
                        children=[
                            ParsedObject(
                                name='FilmConnection',
                                fields=[
                                    ParsedField(name='count', type='int', nullable=True),
                                    ParsedField(name='edges', type='List[FilmEdge]', nullable=True),
                                ],
                                children=[
                                    ParsedObject(
                                        name='FilmEdge',
                                        fields=[
github graphql-python / gql-next / gql / query_parser.py View on Github external
variables = []
        for var in node.variable_definitions:
            ptype, nullable, _ = self.__variable_type_to_python(var.type)
            variables.append(ParsedVariableDefinition(
                name=var.variable.name.value,
                type=ptype,
                nullable=nullable,
                default_value=var.default_value.value if var.default_value else None,
            ))

        parsed_op = ParsedOperation(
            name=name.value,
            type=str(operation.value),
            variables=variables,
            children=[
                ParsedObject(name=f'{name.value}Data')
            ]
        )

        self.parsed.objects.append(parsed_op)  # pylint:disable=no-member
        self.push(parsed_op)
        self.push(parsed_op.children[0])  # pylint:disable=unsubscriptable-object

        return node
github graphql-python / gql-next / gql / query_parser.py View on Github external
@dataclass
class ParsedVariableDefinition:
    name: str
    type: str
    nullable: bool
    default_value: Any = None


@dataclass
class ParsedOperation:
    name: str
    type: str
    variables: List[ParsedVariableDefinition] = field(default_factory=list)
    children: List[ParsedObject] = field(default_factory=list)


NodeT = Union[ParsedOperation, ParsedObject]


@dataclass
class ParsedQuery:
    query: str
    objects: List[NodeT] = field(default_factory=list)
    enums: List[ParsedEnum] = field(default_factory=list)


class FieldToTypeMatcherVisitor(Visitor):

    def __init__(self, schema: GraphQLSchema, type_info: TypeInfo, query: str):
        self.schema = schema
github graphql-python / gql-next / gql / query_parser.py View on Github external
)

        self.current.fields.append(parsed_field)  # TODO: nullables should go to the end

        if not is_scalar_type(underlying_graphql_type):
            if is_enum_type(underlying_graphql_type):
                enum_type = cast(GraphQLEnumType, self.schema.type_map[underlying_graphql_type.name])
                name = enum_type.name
                if not any(e.name == name for e in self.parsed.enums):  # pylint:disable=not-an-iterable
                    parsed_enum = ParsedEnum(
                        name=enum_type.name,
                        values={name: value.value or name for name, value in enum_type.values.items()}
                    )
                    self.parsed.enums.append(parsed_enum)  # pylint:disable=no-member
            else:
                obj = ParsedObject(
                    name=str(underlying_graphql_type)
                )

                self.current.children.append(obj)
                self.push(obj)

        return node