Open orome opened 4 years ago
Do something like as:
view_func = GraphQLView.as_view("graphql", schema=Schema(query=some_api_schema.Query), graphiql=True)
app.add_url_rule("/graphql", view_func=view_func)
Notice the graphiql=True
argument being passed,
@KingDarBoja , I think they mean like this: https://stackoverflow.com/questions/59791068/how-do-i-add-the-explorer-to-graphiql-using-flask-graphql
Using graphiql-explorer.
Do you have an example template that would work? Ive been trying to follow the stack overflow ticket, but Im not a react expert.
Ah, that thing is easy to implement, guess I could add that extension to the graphiql template on https://github.com/graphql-python/graphql-server as all server integration code lives there since v3.
@KingDarBoja , any ideas for a quick fix, ie a template string? I tried myself like the ticket mentioned but had no luck.
@datavistics Best idea should be providing a working example, which make use of the graphiql_template
option as described at https://github.com/graphql-python/graphql-server/blob/master/docs/flask.md . I could write it but would be at the weekend as I'm currently busy these days.
Thanks for responding, and if you wrote it over the weekend that would be hugely helpful.
I tried for longer than I care to admit, but Im just at a loss between the js + react -> html -> jinja. I didnt see how to pass the schema, or some of the other parameters required.
@datavistics I hate doing stuff with React but was able to make it work with a custom template by looking at other repositories which tried to implement it (on JS ofc) like https://github.com/OneGraph/graphiql-explorer/issues/29#issue-517377769 .
My current result
What do you need (and I have done so far) on the graphiql_template
:
Then just pass to GraphQLView
class at graphiql_template
field like below.
from flask import Flask
from graphql_server.flask import GraphQLView
from graphiql_explorer import GRAPHIQL_TEMPLATE, GRAPHIQL_VERSION
from schema import schema
app = Flask(__name__)
app.add_url_rule('/graphql', view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True,
graphiql_template=GRAPHIQL_TEMPLATE,
graphiql_version=GRAPHIQL_VERSION,
))
if __name__ == '__main__':
app.run()
NOTE: I am using graphql-server
beta version so please follow these setup to know how to install flask integration with this or use flask-graphql
beta v3.
Also, some stuff doesn't work at all like clicking on the explorer nodes as I haven't added the rest of options listed at https://github.com/OneGraph/graphiql-explorer-example/blob/master/src/App.js#L171 example but this initial setup should be the way to go.
Speaking of that, I found https://github.com/strawberry-graphql/strawberry/pull/293 which seems to point out some issues regarding graphql-explorer
🤔 I will take a closer look at it later.
@KingDarBoja thanks a ton, but unfortunately I couldnt get it to work. Im using graphene-elastic which depends on graphene < 3
.
@KingDarBoja Is there a way to use this for graphene 2.1.8
and Flask-GraphQL 2.0.1
?
@KingDarBoja Is there a way to use this for
graphene 2.1.8
andFlask-GraphQL 2.0.1
?
Flask-GraphQL 2 supports passing custom graphiql templates as well.
@KingDarBoja Is your working graphiql version with explorer published on github? I can't get it to work and a working example from where to start would be a lifesaver
@KingDarBoja Thanks for this!
Would love to see it get fully developed. I.e. clicking on the nodes fills the query; node selections get updated when query is updated; node fields can be selected.
Has anyone had any luck using graphiql v2?
Is there a way to enable the GraphiQL explorer for a Python (
flask-graphql
) backend?