fastapi: Usage Graphene Subscriptions in FastAPI - Usage of Starlette-Graphene3 failed
I wanted to make the subscriptions of graphene work in FastAPI. Unfortuantely I saw two other repositories who asked a similar thing and no conclusion made there. After some research I found the package starlette-graphene3, which makes uploading files and the subscription possible in Starlette. Due to the usage of the the GraphQLApp-class of starlette i thought, that this is going to work. Unfortunately there is a little problem when using starlette-graphene3 with fastapi:
- When installing starlette-graphene3 I get the error:
ERROR: fastapi 0.63.0 has requirement starlette==0.13.6, but you'll have starlette 0.14.1 which is incompatible., which makes FastAPI not work anymore.
My questions are:
- is it in planning to use a newer Starlette version, that starlette-graphene3 could be used
- Any other way to make subscriptions work in FastAPI?
When trying to use GraphQL like in the documentation of FastAPI with subscriptions i get the error:
"Subscriptions are not allowed. You will need to either use the subscribe function or pass allow_subscriptions=True"
Code to reproduce:
from fastapi import FastAPI
from starlette.graphql import GraphQLApp
import graphene
import asyncio
class Subscription(graphene.ObjectType):
count = graphene.Int(upto=graphene.Int())
async def subscribe_count(root, info, upto=3):
for i in range(upto):
yield i
await asyncio.sleep(1)
app = FastAPI()
app.add_route("/graphql", GraphQLApp(schema=graphene.Schema(subscription=Subscription)))
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (6 by maintainers)
ok now it worked, but still weird 😂. However, can i do
app.add_route("/graphql", GraphQLApp(schema=graphene.Schema(query=Query, mutation=PostMutations, subscription=GraphQL(schema, debug=True))))in order to have all methods? in gernall How to have Query, mutation and subscription methods at ones?solved this is a template for queries, mutatoins and subscriptions with testing everything in one https://github.com/aliscie/fastapi-full-graphql-template
I know all of them it is just painful to not to find a scaffold with all the methods at ones 😔.
@aliscie you can check the documentation to get the main basics or there is some useful links that help me to create JeffQL.
Uninstall the graphene and graphql-core dependency, then re-install
pip install ariadne, that relate to a conflict between the versions.@matthewchung74 Yep thats it