11 files changed
+5380
-1
No files matched your search
+14
@@ -0,0 +1,14 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.prod
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
#Mac specific files
|
||||
.DS_Store
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["env", "stage-2"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
TEAMS_API_URL='https://teams-api.advancedalgos.net/graphql'
|
||||
USERS_API_URL='https://users-api.advancedalgos.net/graphql'
|
||||
KEYVAULT_API_URL='https://keyvault-api.advancedalgos.net/graphql'
|
||||
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.prod
|
||||
|
||||
# Build folder js files
|
||||
build/
|
||||
dist/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
#Mac specific files
|
||||
.DS_Store
|
||||
Generated
+5158
File diff suppressed because it is too large.
Load diff
+19
-1
@@ -4,6 +4,7 @@
|
||||
"description": "Responsible for loading all web modules and running them.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --exec babel-node --presets env,stage-2 src/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
@@ -15,5 +16,22 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/Algoteers/MasterApp/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Algoteers/MasterApp#readme"
|
||||
"homepage": "https://github.com/Algoteers/MasterApp#readme",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"nodemon": "^1.18.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-link-context": "^1.0.9",
|
||||
"apollo-link-http": "^1.5.5",
|
||||
"apollo-server-express": "^1.1.0",
|
||||
"body-parser": "^1.18.3",
|
||||
"dotenv": "^6.1.0",
|
||||
"express": "^4.16.3",
|
||||
"graphql": "^14.0.2",
|
||||
"graphql-tools": "^4.0.0",
|
||||
"node-fetch": "^2.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import fetch from 'node-fetch'
|
||||
import { createHttpLink } from 'apollo-link-http'
|
||||
import { setContext } from 'apollo-link-context'
|
||||
import {
|
||||
makeRemoteExecutableSchema,
|
||||
introspectSchema,
|
||||
transformSchema,
|
||||
RenameTypes,
|
||||
RenameRootFields
|
||||
} from 'graphql-tools'
|
||||
|
||||
import { capitalize } from './utils'
|
||||
|
||||
export const createRemoteSchema = async (uri) => {
|
||||
const makeDatabaseServiceLink = () => createHttpLink({
|
||||
uri: uri,
|
||||
fetch
|
||||
})
|
||||
const databaseServiceSchemaDefinition = await introspectSchema(makeDatabaseServiceLink())
|
||||
|
||||
const http = makeDatabaseServiceLink()
|
||||
|
||||
const link = setContext((request, previousContext) => (
|
||||
{
|
||||
headers: {
|
||||
authorization: previousContext.graphqlContext.headers.authorization || ''
|
||||
}
|
||||
}
|
||||
)).concat(http)
|
||||
|
||||
return makeRemoteExecutableSchema({
|
||||
schema: databaseServiceSchemaDefinition,
|
||||
link: link
|
||||
})
|
||||
}
|
||||
|
||||
export const createTransformedRemoteSchema = async (prefix, uri) => {
|
||||
var schema
|
||||
try {
|
||||
schema = await createRemoteSchema(uri)
|
||||
} catch (error) {
|
||||
console.log(`An error occured while fetching ${prefix} schema :`)
|
||||
console.log(error)
|
||||
return false
|
||||
}
|
||||
const transformedSchema = transformSchema(schema, [
|
||||
new RenameTypes((name) => prefix + capitalize(name)),
|
||||
new RenameRootFields((operation, name) => prefix + capitalize(name))
|
||||
])
|
||||
return transformedSchema
|
||||
}
|
||||
|
||||
export default createRemoteSchema
|
||||
@@ -0,0 +1,71 @@
|
||||
import express from 'express'
|
||||
import bodyParser from 'body-parser'
|
||||
import 'dotenv/config'
|
||||
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
|
||||
import { mergeSchemas } from 'graphql-tools'
|
||||
import { createTransformedRemoteSchema } from './createRemoteSchema'
|
||||
import { teams } from './links'
|
||||
|
||||
async function run () {
|
||||
const transformedTeamsSchema = await createTransformedRemoteSchema('TeamsModule', process.env.TEAMS_API_URL)
|
||||
const transformedUsersSchema = await createTransformedRemoteSchema('UsersModule', process.env.USERS_API_URL)
|
||||
const transformedKeyVaultSchema = await createTransformedRemoteSchema('KeyVaultModule', process.env.KEYVAULT_API_URL)
|
||||
|
||||
var schemas = []
|
||||
var resolvers = {}
|
||||
|
||||
if (transformedTeamsSchema) {
|
||||
schemas.push(transformedTeamsSchema)
|
||||
if (transformedUsersSchema) {
|
||||
schemas.push(teams.linkSchemaDefs)
|
||||
resolvers = Object.assign(resolvers, teams.resolver(transformedUsersSchema))
|
||||
}
|
||||
}
|
||||
if (transformedUsersSchema) {
|
||||
schemas.push(transformedUsersSchema)
|
||||
}
|
||||
if (transformedKeyVaultSchema) {
|
||||
schemas.push(transformedKeyVaultSchema)
|
||||
}
|
||||
|
||||
const schema = mergeSchemas({
|
||||
schemas,
|
||||
resolvers
|
||||
})
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use('/graphql', bodyParser.json(), graphqlExpress(req => {
|
||||
return ({
|
||||
schema: schema,
|
||||
context: req
|
||||
})
|
||||
}))
|
||||
|
||||
app.use(
|
||||
'/graphiql',
|
||||
graphiqlExpress({
|
||||
endpointURL: '/graphql',
|
||||
query: `
|
||||
{
|
||||
TeamsModuleTeams{
|
||||
edges{
|
||||
node{
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
})
|
||||
)
|
||||
|
||||
app.listen(3000)
|
||||
console.log('Server running. Open http://localhost:3000/graphiql to run queries.')
|
||||
}
|
||||
|
||||
try {
|
||||
run()
|
||||
} catch (e) {
|
||||
console.log(e, e.message, e.stack)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import teams from './teams'
|
||||
|
||||
export { teams }
|
||||
@@ -0,0 +1,27 @@
|
||||
export const linkSchemaDefs =
|
||||
`
|
||||
extend type TeamsModuleTeam {
|
||||
ownerUser: UsersModuleUser
|
||||
}
|
||||
`
|
||||
|
||||
export const resolver = (usersSchema) => ({
|
||||
TeamsModuleTeam: {
|
||||
ownerUser: {
|
||||
fragment: `fragment UserFragment on TeamsModuleTeam{owner}`,
|
||||
resolve (parent, args, context, info) {
|
||||
const authId = parent.owner
|
||||
return info.mergeInfo.delegateToSchema({
|
||||
schema: usersSchema,
|
||||
operation: 'query',
|
||||
fieldName: 'UsersModuleUserByAuthId',
|
||||
args: { authId },
|
||||
context,
|
||||
info
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default { resolver, linkSchemaDefs }
|
||||
@@ -0,0 +1,5 @@
|
||||
export const capitalize = (string) => {
|
||||
return (string).charAt(0).toUpperCase() + (string).slice(1)
|
||||
}
|
||||
|
||||
export default capitalize
|
||||
Reference in new issue
Block a user