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
type Query { | |
building_with_id(_id: ID!): Building | |
resident_with_id(_id: ID!): Resident | |
} | |
type Building { | |
id: ID! | |
buildYear: String! | |
residents: [Resident] | |
} |
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
from ariadne import graphql_sync, make_executable_schema, load_schema_from_path, ObjectType, QueryType | |
from ariadne.constants import PLAYGROUND_HTML | |
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
@app.route('/graphql', methods=['GET']) | |
def playground(): | |
return PLAYGROUND_HTML, 200 | |
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
from ariadne import graphql_sync, make_executable_schema, load_schema_from_path, ObjectType, QueryType | |
from ariadne.constants import PLAYGROUND_HTML | |
from flask import Flask, request, jsonify |
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
{ | |
"buildings": [ | |
{ | |
"id": "1", | |
"buildYear": 2009 | |
}, | |
{ | |
"id": "2", | |
"buildYear": 2009 | |
}, |
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
type_defs = load_schema_from_path('schema.graphql') | |
query = QueryType() | |
building = ObjectType('Building') | |
resident = ObjectType('Resident') | |
schema = make_executable_schema(type_defs, [building, resident, 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
import json | |
def building_with_id(_, info, _id): | |
with open('./data/buildings.json') as file: | |
data = json.load(file) | |
for building in data['buildings']: | |
if building['id'] == _id: | |
return building |
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
from ariadne import graphql_sync, make_executable_schema, load_schema_from_path, ObjectType, QueryType | |
from ariadne.constants import PLAYGROUND_HTML | |
from flask import Flask, request, jsonify | |
import resolvers as r | |
app = Flask(__name__) | |
type_defs = load_schema_from_path('schema.graphql') | |
query = QueryType() |
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
def resolve_residents_in_building(building, info): | |
print(building) | |
with open('./data/residents.json') as file: | |
data = json.load(file) | |
residents = [ | |
resident | |
for resident | |
in data['residents'] | |
if resident['building'] | |
== building['id']] |
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
building.set_field('residents', r.resolve_residents_in_building) |