-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e62387
commit 2ec0479
Showing
21 changed files
with
1,331 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module 'minipass-fetch' { | ||
const miniPassfetch: typeof fetch | ||
export default miniPassfetch | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const typeDefs = gql`` | ||
export const typeDefs = gql` | ||
type Query | ||
type Mutation | ||
` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
import { default as gql } from 'graphql-tag' | ||
|
||
export const typeDefs = gql`` | ||
export const typeDefs = gql` | ||
extend type Query { | ||
orders: [Order] | ||
} | ||
interface OrdersResolvers {} | ||
extend type Mutation { | ||
createOrder(input: CreateOrderInput): Order | ||
} | ||
` | ||
|
||
export const resolvers: OrdersResolvers = {} | ||
interface OrdersResolvers { | ||
Query: { | ||
orders: () => Promise<any[]> | ||
} | ||
Mutation: { | ||
createOrder: (_: any, { input }: { input: any }) => Promise<any> | ||
} | ||
} | ||
|
||
export const resolvers: OrdersResolvers = { | ||
Query: { | ||
orders: async () => { | ||
return [ | ||
{ | ||
id: '1', | ||
createdAt: new Date().toISOString(), | ||
updatedAt: new Date().toISOString(), | ||
status: 'CREATED', | ||
amount: 100, | ||
}, | ||
] | ||
}, | ||
}, | ||
Mutation: { | ||
createOrder: async (_: any, { input }: { input: any }) => { | ||
return { | ||
id: '1', | ||
...input, | ||
} | ||
}, | ||
}, | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ApolloServer } from '@apollo/server'; | ||
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'; | ||
import { getSchema } from './core/graphql/schema'; | ||
import { app, httpServer } from './server'; | ||
import { serverConfig } from './config/server'; | ||
import bodyParser from 'body-parser'; | ||
import compression from 'compression'; | ||
import cookieParser from 'cookie-parser'; | ||
const schema = getSchema(); | ||
// The ApolloServer constructor requires two parameters: your schema | ||
// definition and your set of resolvers. | ||
const server = new ApolloServer({ | ||
schema, | ||
introspection: true, | ||
plugins: [ | ||
ApolloServerPluginDrainHttpServer({ httpServer }), | ||
{ | ||
async serverWillStart() { | ||
return { | ||
async drainServer() { | ||
console.log('Draining websocket server before shutdown'); | ||
try { | ||
// TODO: Handle any subscriptions here | ||
} | ||
catch (e) { | ||
console.error('Error draining websocket server / cancelling any subscriptions', e); | ||
} | ||
}, | ||
}; | ||
}, | ||
}, | ||
], | ||
}); | ||
app.use(bodyParser.json()); | ||
app.use(compression()); | ||
app.use(cookieParser()); | ||
server.start().then(() => { }); | ||
httpServer.listen(serverConfig.port, () => { | ||
console.log(`Milady Pool AVS API running on port: ${serverConfig.port}\n`); | ||
}); |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const serverConfig = { | ||
port: 8081, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import gql from 'graphql-tag'; | ||
export const typeDefs = gql ``; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { default as gql } from 'graphql-tag'; | ||
export const typeDefs = gql ``; | ||
export const resolvers = {}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { stitchSchemas } from '@graphql-tools/stitch'; | ||
import { typeDefs as commonTypeDefs } from './extensions/common'; | ||
import { resolvers as ordersResolvers, typeDefs as ordersTypeDefs, } from './extensions/orders'; | ||
import { merge } from 'lodash'; | ||
const resolvers = merge(ordersResolvers); | ||
export const getSchema = () => { | ||
return stitchSchemas({ | ||
resolvers, | ||
typeDefs: [commonTypeDefs, ordersTypeDefs], | ||
}); | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import express from 'express'; | ||
import { createServer } from 'http'; | ||
export const app = express(); | ||
export const httpServer = createServer(app); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import axios from 'axios' | ||
|
||
import Agent from 'agentkeepalive' | ||
|
||
export * from 'axios' | ||
|
||
export const globalHttpsKeepAliveAgent = new Agent.HttpsAgent({ | ||
keepAlive: true, | ||
maxSockets: 15, | ||
maxFreeSockets: 15, | ||
timeout: 60000, // active socket keepalive for 60 seconds | ||
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds | ||
}) | ||
export const globalHttpKeepAliveAgent = new Agent({ | ||
keepAlive: true, | ||
maxSockets: 15, | ||
maxFreeSockets: 15, | ||
timeout: 60000, // active socket keepalive for 60 seconds | ||
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds | ||
}) | ||
|
||
export const axiosInstance = axios.create({ | ||
//keepAlive pools and reuses TCP connections, so it's faster | ||
httpAgent: globalHttpKeepAliveAgent, | ||
httpsAgent: globalHttpsKeepAliveAgent, | ||
//follow up to 10 HTTP 3xx redirects | ||
maxRedirects: 10, | ||
|
||
//cap the maximum content length we'll accept to 50MBs, just in case | ||
maxContentLength: 50 * 1000 * 1000, | ||
}) | ||
|
||
axiosInstance.interceptors.request.use((request) => { | ||
console.log(`[${request.method?.toUpperCase()}]: ${request.url}`) | ||
return request | ||
}) | ||
|
||
export default axiosInstance |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ignore": ["node_modules"], | ||
"watch": [".", ".env"], | ||
"exec": "ts-node scripts/runSingleton.ts --project tsconfig.json", | ||
"ext": "ts" | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import './setupEnv' | ||
import '../api' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dotenv/config' | ||
import '../utils/import-graphql' | ||
import axios from 'axios' | ||
|
||
import { | ||
globalHttpsKeepAliveAgent, | ||
globalHttpKeepAliveAgent, | ||
} from '../lib/axios' | ||
|
||
import fetch from 'minipass-fetch' | ||
import http from 'http' | ||
import https from 'https' | ||
|
||
axios.defaults.httpAgent = globalHttpKeepAliveAgent | ||
axios.defaults.httpsAgent = globalHttpsKeepAliveAgent | ||
http.globalAgent = globalHttpKeepAliveAgent | ||
https.globalAgent = globalHttpsKeepAliveAgent | ||
|
||
// @ts-ignore | ||
global.fetch = fetch | ||
|
||
Object.assign( | ||
BigInt.prototype, | ||
'toJSON', | ||
function (this: typeof BigInt.prototype) { | ||
return this.toString() | ||
} | ||
) | ||
|
||
// TODO: Need to add ws... |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { parse } from 'graphql' | ||
import { readFileSync } from 'fs' | ||
import { createRequire } from 'module' | ||
|
||
const require = createRequire(import.meta.url) | ||
|
||
export const supportImportGraphQL = () => { | ||
const VALID_EXTENSIONS = ['graphql', 'graphqls', 'gql', 'gqls'] | ||
|
||
function handleModule(m: typeof module, filename: string) { | ||
const content = readFileSync(filename, 'utf-8') | ||
|
||
m.exports = parse(content) | ||
} | ||
|
||
VALID_EXTENSIONS.forEach((ext) => { | ||
require.extensions[`.${ext}`] = handleModule | ||
}) | ||
} | ||
|
||
supportImportGraphQL() |
Oops, something went wrong.