diff --git a/fitbit-challenges/.pre-commit-config.yaml b/fitbit-challenges/.pre-commit-config.yaml new file mode 100644 index 00000000..1cb6f82e --- /dev/null +++ b/fitbit-challenges/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + - repo: https://github.com/pre-commit/mirrors-eslint + rev: 'v7.15.0' # Use the sha / tag you want to point at + hooks: + - id: eslint + files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx + types: [file] + args: ["--fix"] + additional_dependencies: + - eslint@7.15.0 + - eslint-config-standard@16.0.2 + - eslint-plugin-import@2.22.1 + - eslint-plugin-node@11.1.0 + - eslint-plugin-promise@4.2.1 + - eslint-plugin-react@7.21.5 diff --git a/fitbit-challenges/README.md b/fitbit-challenges/README.md index 3abe485d..9b11dc18 100644 --- a/fitbit-challenges/README.md +++ b/fitbit-challenges/README.md @@ -1 +1 @@ -# fitbit-challenges \ No newline at end of file +# fitbit-challenges diff --git a/fitbit-challenges/api/Dockerfile b/fitbit-challenges/api/Dockerfile index c01013b8..2d5781a2 100644 --- a/fitbit-challenges/api/Dockerfile +++ b/fitbit-challenges/api/Dockerfile @@ -3,7 +3,7 @@ FROM python:3-alpine EXPOSE 5000/tcp RUN apk update && \ - apk add --virtual build-deps gcc python3-dev musl-dev && \ + apk add --virtual build-deps gcc git python3-dev musl-dev && \ apk add postgresql-dev WORKDIR /usr/src/app diff --git a/fitbit-challenges/api/app.py b/fitbit-challenges/api/app.py index fc519b13..f3f6876b 100644 --- a/fitbit-challenges/api/app.py +++ b/fitbit-challenges/api/app.py @@ -1,7 +1,7 @@ import os from flask import Flask -from flask_graphql import GraphQLView +from graphql_server.flask import GraphQLView from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_cors import CORS diff --git a/fitbit-challenges/api/graphql/schema.py b/fitbit-challenges/api/graphql/schema.py index de7211c8..49ce977a 100644 --- a/fitbit-challenges/api/graphql/schema.py +++ b/fitbit-challenges/api/graphql/schema.py @@ -1,10 +1,21 @@ -from graphql import GraphQLObjectType, GraphQLSchema +from graphql import GraphQLObjectType, GraphQLSchema, GraphQLField, GraphQLString + + +def get_test_field(*args, **kwargs) -> str: + return "hello world!" def Schema(models): return GraphQLSchema( query=GraphQLObjectType( - name="RootQueryType", - fields={}, + name="Query", + fields={ + "test": GraphQLField( + GraphQLString, + args={}, + resolve=get_test_field, + description="Test field", + ) + }, ) ) diff --git a/fitbit-challenges/api/migrations/README b/fitbit-challenges/api/migrations/README index 98e4f9c4..2500aa1b 100644 --- a/fitbit-challenges/api/migrations/README +++ b/fitbit-challenges/api/migrations/README @@ -1 +1 @@ -Generic single-database configuration. \ No newline at end of file +Generic single-database configuration. diff --git a/fitbit-challenges/api/requirements.txt b/fitbit-challenges/api/requirements.txt index 147a7d39..cd4d4bb4 100644 --- a/fitbit-challenges/api/requirements.txt +++ b/fitbit-challenges/api/requirements.txt @@ -1,9 +1,11 @@ -Flask -Flask-Migrate +Flask>=2.2 +Flask-Migrate>=4.0.4 psycopg2 +pylint sqlalchemy -Flask-SQLAlchemy -graphql-core==2.2 -flask_graphql +Flask-SQLAlchemy>=3.0.3 +graphql-core +git+https://github.com/graphql-python/graphql-server@8b9639e1575a20c7322fb8f19459d743d7201410#egg=graphql-server[flask] flask-cors -black \ No newline at end of file +pre-commit +black diff --git a/fitbit-challenges/docker-compose.yaml b/fitbit-challenges/docker-compose.yaml index fd2a4e50..db0c0ff0 100644 --- a/fitbit-challenges/docker-compose.yaml +++ b/fitbit-challenges/docker-compose.yaml @@ -16,7 +16,7 @@ services: - DB_USERNAME=admin - DB_PASSWORD=development - DATABASE_NAME=api_development - - FRONTEND_HOST=192.168.1.5 + - FRONTEND_HOST=localhost - FRONTEND_PORT=5001 migration: build: @@ -56,5 +56,5 @@ services: - ./frontend/src:/usr/src/app/src environment: - PORT=5001 - - REACT_APP_API_HOST=192.168.1.5 - - REACT_APP_API_PORT=5000 \ No newline at end of file + - REACT_APP_API_HOST=127.0.0.1 + - REACT_APP_API_PORT=5000 diff --git a/fitbit-challenges/frontend/package-lock.json b/fitbit-challenges/frontend/package-lock.json index 83be6dd5..ea51473c 100644 --- a/fitbit-challenges/frontend/package-lock.json +++ b/fitbit-challenges/frontend/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "@apollo/client": "^3.7.10", + "@apollo/react-testing": "^4.0.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", @@ -85,6 +86,14 @@ } } }, + "node_modules/@apollo/react-testing": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@apollo/react-testing/-/react-testing-4.0.0.tgz", + "integrity": "sha512-P7Z/flUHpRRZYc3FkIqxZH9XD3FuP2Sgks1IXqGq2Zb7qI0aaTfVeRsLYmZNUcFOh2pTHxs0NXgPnH1VfYOpig==", + "dependencies": { + "@apollo/client": "latest" + } + }, "node_modules/@babel/code-frame": { "version": "7.18.6", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", diff --git a/fitbit-challenges/frontend/package.json b/fitbit-challenges/frontend/package.json index 96fdc39c..6917e947 100644 --- a/fitbit-challenges/frontend/package.json +++ b/fitbit-challenges/frontend/package.json @@ -4,6 +4,7 @@ "private": true, "dependencies": { "@apollo/client": "^3.7.10", + "@apollo/react-testing": "^4.0.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", diff --git a/fitbit-challenges/frontend/src/App.js b/fitbit-challenges/frontend/src/App.js index 22bc0405..bc68784c 100644 --- a/fitbit-challenges/frontend/src/App.js +++ b/fitbit-challenges/frontend/src/App.js @@ -5,9 +5,23 @@ import { Route } from "react-router-dom"; +import { useQuery, gql } from '@apollo/client'; + +const TEST_QUERY = gql` + query Test { + test + } +`; + function MyComponent() { + const { loading, error, data } = useQuery(TEST_QUERY); + + if (loading) return
Loading...
; + + if (error) returnError : {error.message}
; + return ( -