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
| # delete_book.py | |
| import mysql.connector | |
| db_connection = mysql.connector.connect( | |
| host="localhost", | |
| user="root", | |
| password="password1", | |
| database="library" | |
| ) |
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
| # update_book.py | |
| import mysql.connector | |
| db_connection = mysql.connector.connect( | |
| host="localhost", | |
| user="root", | |
| password="password1", | |
| database="library" | |
| ) |
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
| # read_books.py | |
| import mysql.connector | |
| db_connection = mysql.connector.connect( | |
| host="localhost", | |
| user="root", | |
| password="password1", | |
| database="library" | |
| ) |
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
| # create_book.py | |
| import mysql.connector | |
| db_connection = mysql.connector.connect( | |
| host="localhost", | |
| user="root", | |
| password="password1", | |
| database="library" | |
| ) |
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
| # 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. |
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
| # 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. |
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
| 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. |
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
| 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: |
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
| # 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(): |
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
| 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") |
NewerOlder