enable CORS

This commit is contained in:
Ruidy 2020-10-25 12:31:33 +01:00
parent 4723d7734b
commit d4bf69c102
6 changed files with 46 additions and 4 deletions

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

25
.idea/watcherTasks.xml Normal file
View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="true">
<option name="arguments" value="$FileName$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="black" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="black" />
<option name="runOnExternalChanges" value="false" />
<option name="scopeName" value="All Places" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
</component>
</project>

View file

@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true verify_ssl = true
[dev-packages] [dev-packages]
yapf = "*" black = "*"
[packages] [packages]
fastapi = "*" fastapi = "*"

View file

@ -1,4 +1,4 @@
# Todo GraphQL # Python GraphQL API
Python GraphQL API template application Python GraphQL API template application

View file

@ -1,11 +1,21 @@
import graphene import graphene
from fastapi import FastAPI from fastapi import FastAPI
from starlette.graphql import GraphQLApp from starlette.graphql import GraphQLApp
from starlette.middleware.cors import CORSMiddleware
from app.schema.mutations.mutations import Mutations from app.schema.mutations.mutations import Mutations
from app.schema.queries.todo import TodoQuery from app.schema.queries.todo import TodoQuery
origins = ["*"]
app = FastAPI() app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_route( app.add_route(
"/", "/", GraphQLApp(schema=graphene.Schema(query=TodoQuery, mutation=Mutations))
GraphQLApp(schema=graphene.Schema(query=TodoQuery, mutation=Mutations))) )

View file

@ -25,5 +25,6 @@ class ResponseField(graphene.ObjectType):
is_success = graphene.Boolean(default_value=True) is_success = graphene.Boolean(default_value=True)
error_message = graphene.String() error_message = graphene.String()
class TodoResponseField(ResponseField): class TodoResponseField(ResponseField):
todo = graphene.Field(TodoType) todo = graphene.Field(TodoType)