This file contains hidden or 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 { Query, Resolver, Arg, Mutation, createUnionType } from 'type-graphql'; | |
| import { Abilities, Pokemon, PokemonAbilities, Types } from '../models'; | |
| const PokemonAbilitiesUnion = createUnionType({ | |
| name: 'PokemonAbilitiesUnion', | |
| types: () => [ Pokemon, PokemonAbilities ] as const, | |
| }); | |
| @Resolver() | |
| export class Resolvers { |
This file contains hidden or 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 { createConnection } from 'typeorm'; | |
| import { Abilities, Pokemon, PokemonAbilities, Types } from '../models'; | |
| export const init_db = async() => { | |
| const connection = await createConnection(); | |
| await connection.dropDatabase(); | |
| await connection.synchronize(); | |
| // Types | |
| const electric = new Types(); |
This file contains hidden or 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 { Field, ID, ObjectType } from 'type-graphql'; | |
| import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; | |
| @Entity() | |
| @ObjectType() | |
| export class Abilities extends BaseEntity { | |
| @Field(() => ID) | |
| @PrimaryGeneratedColumn() | |
| id: number | null = null; |
This file contains hidden or 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
Show hidden characters
| { | |
| "compilerOptions": { | |
| "target": "es2018", | |
| "module": "commonjs", | |
| "lib": ["es2018", "esnext.asynciterable"], | |
| "sourceMap": true, | |
| "outDir": "./dist", | |
| "rootDir": "./src", | |
| "removeComments": true, | |
| "strict": true, |
This file contains hidden or 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
| # /main.py | |
| from books.app import app | |
| from books.database.init_db import init_db | |
| def main(): | |
| init_db() | |
| app.run() |
This file contains hidden or 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
| # /books/app.py | |
| from flask import Flask | |
| from flask_graphql import GraphQLView | |
| from .database.db_session import db_session | |
| from .schema.schema import schema | |
| app = Flask(__name__) | |
| app.debug = True |
This file contains hidden or 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
| # /books/utils/input_to_dictionary.py | |
| from graphql_relay.node.node import from_global_id | |
| def input_to_dictionary(input): | |
| """Method to convert Graphene inputs into dictionary""" | |
| dictionary = {} | |
| for key in input: | |
| # Convert GraphQL global id to database id |
This file contains hidden or 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
| # /books/schema/mutation.py | |
| import graphene | |
| from ..database.db_session import db_session | |
| from ..models.books import Books as BooksModel | |
| from ..types.books import Books, CreateBookInput | |
| from ..utils.input_to_dictionary import input_to_dictionary | |
This file contains hidden or 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
| # /books/database/base.py | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from .db_session import db_session | |
| Base = declarative_base() | |
| Base.query = db_session.query_property() |
This file contains hidden or 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
| # /books/types/books.py | |
| import graphene | |
| from graphene_sqlalchemy import SQLAlchemyObjectType | |
| from ..models.books import Books as BooksModel | |
| class Books(SQLAlchemyObjectType): | |
| class Meta: |