Skip to content

Commit

Permalink
feat: prepare graphql service to be deployed (#40)
Browse files Browse the repository at this point in the history
On this PR;
- Add env configurations
- Disable docker env for now
- Point graphql API to fuel-client beta-4 live env
  • Loading branch information
luizstacio authored Sep 23, 2023
1 parent 985fa0f commit 2dd8188
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 239 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
pnpm-lock.yaml
storybook-static
.next
graphql.schema.json
4 changes: 3 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
start:
# sh ./scripts/start.sh
docker compose start
# docker compose up
echo "Docker env is temporary disabled on this project";
echo "Run pnpm dev for development";

down:
docker compose down
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"clean:indexer": "pnpm --filter=indexer clean",
"deploy:indexer": "pnpm --filter=indexer run deploy",
"deps:update": "updates -gu && pnpm -r exec updates -gu",
"dev": "pnpm turbo:run dev --filter=!indexer",
"dev:app": "pnpm --filter=app dev",
"dev:graphql": "run-s node:start && pnpm --filter=graphql dev",
"dev:indexer": "pnpm --filter=indexer dev",
"dev:graphql": "pnpm --filter=graphql dev",
"dev:indexer": "pnpm --filter=indexer dev:indexer",
"lint": "run-s lint:check prettier:check",
"lint:check": "pnpm turbo:run lint",
"node:clean": "make -C ./docker clean",
Expand Down Expand Up @@ -85,6 +86,7 @@
"overrides": {
"glob-parent@<5.1.2": ">=5.1.2",
"trim@<0.0.3": ">=0.0.3",
"graphql": ">=16.8.1",
"trim-newlines@<3.0.1": ">=3.0.1",
"terser@>=5.0.0 <5.14.2": ">=5.14.2",
"terser@<4.8.1": ">=4.8.1",
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FUEL_PROVIDER_URL=http://beta-4.fuel.network/graphql
18 changes: 14 additions & 4 deletions packages/graphql/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6618,7 +6618,11 @@
"name": "include",
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
"isRepeatable": false,
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
Expand All @@ -6642,7 +6646,11 @@
"name": "skip",
"description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
"isRepeatable": false,
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
Expand All @@ -6666,7 +6674,9 @@
"name": "specifiedBy",
"description": "Exposes a URL that specifies the behavior of this scalar.",
"isRepeatable": false,
"locations": ["SCALAR"],
"locations": [
"SCALAR"
],
"args": [
{
"name": "url",
Expand All @@ -6688,4 +6698,4 @@
}
]
}
}
}
6 changes: 4 additions & 2 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"scripts": {
"dev": "ts-node-dev -r tsconfig-paths/register --transpile-only --watch ./src/**/*, src/index.ts",
"dev": "ts-node-dev -r tsconfig-paths/register --transpile-only --watch ./src/**/*, src/bin.ts",
"start": "ts-node -r tsconfig-paths/register --transpile-only src/bin.ts",
"lint": "eslint .",
"codegen": "gql-gen --config codegen.yml",
"build": "pnpm codegen && tsup --dts",
"build": "pnpm codegen && tsup",
"prepare": "pnpm build"
},
"dependencies": {
Expand All @@ -23,6 +24,7 @@
"@graphql-tools/stitch": "^9.0.1",
"@graphql-tools/url-loader": "^8.0.0",
"cors": "^2.8.5",
"dotenv": "16.3.1",
"express": "^4.18.2",
"graphql": "^16.8.0",
"graphql-http": "^1.22.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/graphql/src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dotenv from 'dotenv';
dotenv.config();

import app from './';

// Start the server:
app.listen(4444, () =>
console.log('🚀 Explorer api running at http://localhost:4444/graphql'),
);
10 changes: 5 additions & 5 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import cors from 'cors';
import express from 'express';
import expressPlayground from 'graphql-playground-middleware-express';
import { startGraphql } from '~/startGraphql';
import { requireEnv } from '~/utils';

const { FUEL_PROVIDER_URL } = requireEnv(['FUEL_PROVIDER_URL']);

// Create a server:
const app = express();
Expand All @@ -20,9 +23,6 @@ app.get(
);

// Start graphql server
startGraphql('http://localhost:4000/graphql', app);
startGraphql(FUEL_PROVIDER_URL, app);

// Start the server:
app.listen(4444, () =>
console.log('🚀 Explorer api running at http://localhost:4444/graphql'),
);
export default app;
1 change: 1 addition & 0 deletions packages/graphql/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './graphqlFetch';
export * from './getFieldsValues';
export * from './requireEnv';
12 changes: 12 additions & 0 deletions packages/graphql/src/utils/requireEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function requireEnv<
A extends string[],
B extends { [key in A[number]]: string },
>(keys: string[]): B {
return keys.reduce((ret, key) => {
if (!process.env[key]) {
throw new Error(`Environment variable ${key} is required`);
}
ret[key] = process.env[key]!;
return ret;
}, {} as B);
}
1 change: 1 addition & 0 deletions packages/graphql/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from 'tsup';

export default defineConfig(() => ({
dts: true,
entry: { index: 'src/generated/graphql.ts' },
minify: process.env.NODE_ENV === 'production' ? 'terser' : false,
}));
Loading

0 comments on commit 2dd8188

Please sign in to comment.