AttributeError on Graphqlview
vallode opened this issue · 1 comments
vallode commented
Cannot find much information about this and struggling to debug myself:
AttributeError: 'dict' object has no attribute 'decode'
Error appears when accessing the graphql IDE with a minimal setup:
class Query(graphene.ObjectType):
node = relay.Node.Field()
schema = graphene.Schema(query=Query)
app.add_url_rule(
"/graphql",
view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True),
)
All queries are faced with this error, without the graphql IDE the endpoint is fine.
vallode commented
Jumped to conclusions, we were using FlaskAPI which was hijacking the parsing of data sent back to the graphql interface. If anyone stumbles on this issue you have to create a custom parser like so:
class GraphQLParser(BaseParser):
media_type = "application/json"
def parse(self, stream, media_type, **options):
return stream.read()
And use it in your view func definition like so:
app.add_url_rule(
"/graphql",
view_func=set_parsers(GraphQLParser)(
GraphQLView.as_view("graphql", schema=schema, graphiql=True)
),
)