mirror of
https://github.com/rjNemo/graphql_python_template
synced 2026-06-06 02:26:47 +00:00
enable CORS
This commit is contained in:
parent
4723d7734b
commit
d4bf69c102
6 changed files with 46 additions and 4 deletions
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal 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
25
.idea/watcherTasks.xml
Normal 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>
|
||||||
2
Pipfile
2
Pipfile
|
|
@ -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 = "*"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Todo GraphQL
|
# Python GraphQL API
|
||||||
|
|
||||||
Python GraphQL API template application
|
Python GraphQL API template application
|
||||||
|
|
||||||
|
|
|
||||||
14
app/main.py
14
app/main.py
|
|
@ -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)))
|
)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue