Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strawberry-graphql has a problem with IntrospectionQuery #685

Open
mstrumeck opened this issue Nov 8, 2023 · 5 comments
Open

Strawberry-graphql has a problem with IntrospectionQuery #685

mstrumeck opened this issue Nov 8, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@mstrumeck
Copy link

Bug Description

Hi! I've decided to use Robyn together with strawberry-graphql but is seems it not working properly. Robyn has a problem with rendering the answer from the standard introspection query. With the following code:

app = robyn.Robyn(__file__)


@app.post("/graphql")
async def handle_api_request(request: robyn.Request) -> robyn.jsonify:
    body = request.json()
    query = body["query"]
    variables = body.get("variables")
    context = {}
    root_value = body.get("root_value", None)
    operation_name = body.get("operation_name", None)
    data = await schema.execute(
        query,
        variables,
        context,
        root_value,
        operation_name,
    )
    return robyn.jsonify({
        "data": (data.data),
        **({"errors": data.errors} if data.errors else {}),
        **({"extensions": data.extensions} if data.extensions else {}),
    })


@app.get("/graphql", const=True)
async def handle_api_playground_request(request: robyn.Request):
    return {
        "description": strawberry.utils.graphiql.get_graphiql_html(),
        "headers": {
            "Content-Type": "text/html"
        }
    }

I going to always get the following response:

ERROR:strawberry.execution:Syntax Error: Unexpected <EOF>.

GraphQL request:1:1869
1 | "\n    query IntrospectionQuery {\n      __schema {\n        \n        queryType
  |  { name }\n        mutationType { name }\n        subscriptionType { name }\n   
  |      types {\n          ...FullType\n        }\n        directives {\n          
  | name\n          description\n          \n          locations\n          args(inc
  | ludeDeprecated: true) {\n            ...InputValue\n          }\n        }\n    
  |   }\n    }\n\n    fragment FullType on __Type {\n      kind\n      name\n      d
  | escription\n      \n      fields(includeDeprecated: true) {\n        name\n     
  |    description\n        args(includeDeprecated: true) {\n          ...InputValue
  | \n        }\n        type {\n          ...TypeRef\n        }\n        isDeprecat
  | ed\n        deprecationReason\n      }\n      inputFields(includeDeprecated: tru
  | e) {\n        ...InputValue\n      }\n      interfaces {\n        ...TypeRef\n  
  |     }\n      enumValues(includeDeprecated: true) {\n        name\n        descri
  | ption\n        isDeprecated\n        deprecationReason\n      }\n      possibleT
  | ypes {\n        ...TypeRef\n      }\n    }\n\n    fragment InputValue on __Input
  | Value {\n      name\n      description\n      type { ...TypeRef }\n      default
  | Value\n      isDeprecated\n      deprecationReason\n    }\n\n    fragment TypeRe
  | f on __Type {\n      kind\n      name\n      ofType {\n        kind\n        nam
  | e\n        ofType {\n          kind\n          name\n          ofType {\n       
  |      kind\n            name\n            ofType {\n              kind\n         
  |      name\n              ofType {\n                kind\n                name\n 
  |                ofType {\n                  kind\n                  name\n       
  |            ofType {\n                    kind\n                    name\n       
  |            }\n                }\n              }\n            }\n          }\n  
  |       }\n      }\n    }\n  "
  |                             ^
ERROR:robyn.server:Error while executing route function for endpoint `/graphql`: 

That's happening always when I trying call http://localhost:8080/graphql with GET

Steps to Reproduce

  • Create directory with Robyn app
  • Init poetry.toml file
  • Add python=3.12.0, robyn=^0.44.2, uvloop=^0.19.0, strawberry-graphql=^0.212.0
  • To the src.py file add code mentioned in bug description
  • Run server with python src.py --dev
  • Try call http://localhost:8080/graphql in you browser

Your operating system

Linux

Your Python version (python --version)

3.12

Your Robyn version

latest

Additional Info

No response

@mstrumeck mstrumeck added the bug Something isn't working label Nov 8, 2023
@sansyrox
Copy link
Member

sansyrox commented Nov 8, 2023

Hey @mstrumeck 👋

Thank you for choosing Robyn 😄 Can you please share your schema class?

@patrick91
Copy link
Contributor

@sansyrox here's a minimal reproduction:

import robyn

import strawberry

app = robyn.Robyn(__file__)


@strawberry.type
class Query:
    hello: str = strawberry.field(resolver=lambda: "Hello, world!")


schema = strawberry.Schema(query=Query)


@app.post("/graphql")
async def handle_api_request(request: robyn.Request) -> robyn.jsonify:
    import json
    # note this
    body = json.loads(request.body)
    query = str(body["query"])
    variables = body.get("variables")

    data = await schema.execute(
        query,
        variables,
    )

    return robyn.jsonify(
        {
            "data": (data.data),
            **({"errors": data.errors} if data.errors else {}),
            **({"extensions": data.extensions} if data.extensions else {}),
        }
    )


@app.get("/graphql", const=True)
async def handle_api_playground_request(request: robyn.Request):
    from strawberry.http.ides import get_graphql_ide_html

    return {"description": get_graphql_ide_html(graphql_ide="apollo-sandbox"), "headers": {"Content-Type": "text/html"}}


app.start(port=8080, host="0.0.0.0")  # host is optional, defaults to 127.0.0.1

btw using json.loads works, not sure why request.json() doesn't work properly

@sansyrox
Copy link
Member

sansyrox commented Nov 8, 2023

Thanks @patrick91 , but it is still not working for me

image

@patrick91
Copy link
Contributor

patrick91 commented Nov 8, 2023

@sansyrox can you show me your cli?

@sansyrox
Copy link
Member

sansyrox commented Nov 8, 2023

@patrick91 , here you go

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants