This repository has been archived by the owner on Oct 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from erebus1/add-more-integration-tests
add external types integration test
- Loading branch information
Showing
11 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
from graphene import ObjectType, String, Schema | ||
from graphene_federation import build_schema | ||
from graphene import ObjectType, String, Int, List, NonNull | ||
from graphene_federation import build_schema, extend, external | ||
|
||
|
||
@extend(fields='id') | ||
class FileNode(ObjectType): | ||
id = external(Int(required=True)) | ||
|
||
|
||
class Post(ObjectType): | ||
id = Int(required=True) | ||
title = String(required=True) | ||
text = String(required=True) | ||
files = List(NonNull(FileNode)) | ||
|
||
|
||
class Query(ObjectType): | ||
# this defines a Field `hello` in our Schema with a single Argument `name` | ||
hello = String(name=String(default_value="stranger")) | ||
goodbye = String() | ||
posts = List(NonNull(Post)) | ||
|
||
# our Resolver method takes the GraphQL context (root, info) as well as | ||
# Argument (name) for the Field and returns data for the query Response | ||
def resolve_hello(root, info, name): | ||
return f'Hello {name}!' | ||
def resolve_posts(root, info): | ||
return [ | ||
Post(id=1, title='title1', text='text1', files=[FileNode(id=1)]), | ||
Post(id=2, title='title2', text='text2', files=[FileNode(id=2), FileNode(id=3)]), | ||
Post(id=3, title='title3', text='text3'), | ||
] | ||
|
||
def resolve_goodbye(root, info): | ||
return 'See ya!' | ||
|
||
schema = build_schema(Query) | ||
|
||
schema = build_schema(query=Query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.6-alpine3.9 | ||
|
||
WORKDIR project | ||
|
||
COPY ./requirements.txt ./ | ||
RUN pip install -r requirements.txt | ||
|
||
EXPOSE 5000 | ||
CMD [ "python", "./src/app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
graphene==2.1.7 | ||
flask==1.1.1 | ||
flask_graphql==2.0.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from flask import Flask | ||
|
||
from flask_graphql import GraphQLView | ||
from schema import schema | ||
|
||
app = Flask(__name__) | ||
app.debug = True | ||
|
||
app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from graphene import ObjectType, String, Int, Field | ||
from graphene_federation import build_schema, key | ||
|
||
|
||
@key(fields='id') | ||
class FileNode(ObjectType): | ||
id = Int(required=True) | ||
name = String(required=True) | ||
|
||
def __resolve_reference(self, info, **kwargs): | ||
# todo test raise exception here | ||
return FileNode(id=self.id, name=f'file_{self.id}') | ||
|
||
|
||
class Query(ObjectType): | ||
# todo support query w/o root fields | ||
file = Field(lambda: FileNode) | ||
|
||
|
||
schema = build_schema(Query, types=[FileNode]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters