How to use the gql.query_parser.InvalidQueryError 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
query ShouldFail {
          allFilms {
            totalCount
            edges {
              node {
                title
                nonExistingField
              }
            }
          }
        }
    """

    parser = QueryParser(swapi_schema)

    with pytest.raises(InvalidQueryError) as excinfo:
        parser.parse(query)

    print(str(excinfo))
github graphql-python / gql-next / gql / query_parser.py View on Github external
def parse(self, query: str, should_validate: bool = True) -> ParsedQuery:
        document_ast = parse(query)
        operation = get_operation_ast(document_ast)

        if not operation.name:
            raise AnonymousQueryError()

        if should_validate:
            errors = validate(self.schema, document_ast)
            if errors:
                raise InvalidQueryError(errors)

        type_info = TypeInfo(self.schema)
        visitor = FieldToTypeMatcherVisitor(self.schema, type_info, query)
        visit(document_ast, TypeInfoVisitor(type_info, visitor))
        result = visitor.parsed
        return result
github graphql-python / gql-next / gql / codec / register.py View on Github external
def gql_decode(value, **_):
    decoded, decoded_length = utf_8.decode(value)
    decoded = decoded.replace('# coding: gql', '')
    try:
        bio = BytesIO(decoded.encode('utf-8'))
        result = gql_transform(bio)
        return result, decoded_length
    except InvalidQueryError:
        raise
    except Exception as ex:
        return decoded, decoded_length
github graphql-python / gql-next / gql / cli.py View on Github external
click.echo(f'Parsing {filename} ... ', nl=False)
    with open(filename, 'r') as fin:
        query = fin.read()
        try:
            parsed = parser.parse(query)
            rendered = renderer.render(parsed)
            with open(target_filename, 'w') as outfile:
                outfile.write(rendered)
                click.secho('Success!', fg='bright_white')

        except AnonymousQueryError:
            click.secho('Failed!', fg='bright_red')
            click.secho('\tQuery is missing a name', fg='bright_black')
            safe_remove(target_filename)
        except InvalidQueryError as invalid_err:
            click.secho('Failed!', fg='bright_red')
            click.secho(f'\t{invalid_err}', fg='bright_black')
            safe_remove(target_filename)