Skip to content

Instantly share code, notes, and snippets.

View ericjaychi's full-sized avatar
💻

Eric Chi ericjaychi

💻
View GitHub Profile
# delete_book.py
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
password="password1",
database="library"
)
# update_book.py
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
password="password1",
database="library"
)
# read_books.py
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
password="password1",
database="library"
)
# create_book.py
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
password="password1",
database="library"
)
# create_table.py
# Import the MySQL connector that was installed. This allows us to speak to MySQL.
import mysql.connector
# Establish the connection to the database.
db_connection = mysql.connector.connect(
# The domain in which the databse resides. Since it is local on our machine, it is localhost.
host="localhost",
# The default user for MySQL is root.
# create_database.py
# Import the MySQL connector that was installed. This allows us to speak to MySQL.
import mysql.connector
# Establish the connection to the database.
db_connection = mysql.connector.connect(
# The domain in which the databse resides. Since it is local on our machine, it is localhost.
host="localhost",
# The default user for MySQL is root.
from api import app, db
from ariadne import load_schema_from_path, make_executable_schema, graphql_sync, snake_case_fallback_resolvers, \
ObjectType
from ariadne.constants import PLAYGROUND_HTML
from flask import request, jsonify
from api.queries import get_books_resolver
from api.mutations import create_book_resolver
# Defines the execution type that wishes to be done. In this case we defined a Query type inside schema.graphql.
from .models import Book
from api import db
from ariadne import convert_kwargs_to_snake_case
# Creates a new Book into the database.
@convert_kwargs_to_snake_case
def create_book_resolver(obj, info, title, author, isbn):
try:
# Enables a GET endpoint for Flask under the "/graphql" route.
@app.route("/graphql", methods=["GET"])
def graphql_playground():
# Returns the UI for the Playground when "/graphql" is hit within your application.
return PLAYGROUND_HTML, 200
# Enables a POST endpoint for Flask under the "/graphql" route.
@app.route("/graphql", methods=["POST"])
def graphql_server():
from api import app, db
from ariadne import load_schema_from_path, make_executable_schema, graphql_sync, snake_case_fallback_resolvers, ObjectType
from ariadne.constants import PLAYGROUND_HTML
from flask import request, jsonify
from api.queries import get_books_resolver
# Defines the execution type that wishes to be done. In this case we defined a Query type inside schema.graphql.
# This will allow us to tie a resolver to a method within the schema.graphql file.
query = ObjectType("Query")