-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds basic support for remote schemas/schema stitching (#952)
- Loading branch information
1 parent
5b6a386
commit 512ee6f
Showing
154 changed files
with
7,294 additions
and
997 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ npm-debug.log | |
*.DS_Store | ||
.tern-project | ||
test-server-output | ||
.vscode |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,15 @@ | ||
# GraphQL Server Boilerplates | ||
|
||
Hasura GraphQL Engine can combine schemas from multiple remote GraphQL servers | ||
and expose them at a single endpoint. You can write these GraphQL servers in any | ||
language and Hasura takes care of stitching together the schema from these | ||
servers ([read more](../../../remote-schemas.md)). | ||
|
||
This directory contains boilerplates for writing GraphQL servers using various | ||
languages and frameworks. | ||
|
||
- [Docs on Remote Schemas](https://docs.hasura.io/1.0/graphql/manual/remote-schemas/index.html) | ||
|
||
## Architecture | ||
|
||
![Remote schema architecture diagram](../../../assets/remote-schemas-arch.png) |
2 changes: 2 additions & 0 deletions
2
community/boilerplates/graphql-servers/nodejs-apollo/.gitignore
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 @@ | ||
node_modules | ||
package-lock.json |
11 changes: 11 additions & 0 deletions
11
community/boilerplates/graphql-servers/nodejs-apollo/Dockerfile
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 @@ | ||
FROM node:8 | ||
|
||
WORKDIR /server | ||
|
||
COPY ./package.json /server/ | ||
|
||
RUN npm install | ||
|
||
COPY . /server/ | ||
|
||
CMD ["npm", "start"] |
57 changes: 57 additions & 0 deletions
57
community/boilerplates/graphql-servers/nodejs-apollo/README.md
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,57 @@ | ||
# GraphQL server using NodeJS and Apollo | ||
|
||
A boilerplate Python GraphQL Server using NodeJS and [Apollo Server](https://www.apollographql.com/docs/apollo-server/) | ||
|
||
## Deploying | ||
|
||
Clone the repo: | ||
|
||
```bash | ||
git clone https://github.com/hasura/graphql-engine | ||
cd graphql-engine/community/boilerplates/graphql-servers/nodejs-apollo | ||
``` | ||
|
||
### Using Zeit Now | ||
|
||
Install the [Zeit Now](https://zeit.co/now) CLI: | ||
|
||
```bash | ||
npm install -g now | ||
``` | ||
|
||
Deploy the server: | ||
```bash | ||
now | ||
``` | ||
|
||
Get the URL and make a sample query: | ||
```bash | ||
curl https://app-name-something.now.sh/graphql \ | ||
-H 'Content-Type:application/json' \ | ||
-d'{"query":"{ hello }"}' | ||
|
||
{"data":{"hello":"Hello World!"}} | ||
``` | ||
|
||
You can also visit the now url to open GraphiQL. | ||
|
||
## Running locally | ||
Running the server locally: | ||
|
||
```bash | ||
npm install | ||
npm start | ||
``` | ||
|
||
Running the server using Docker: | ||
|
||
```bash | ||
docker build -t nodejs-apollo-graphql . | ||
docker run -p 4000:4000 nodejs-apollo-graphql | ||
``` | ||
|
||
GraphQL endpoint will be `http://localhost:4000/graphql`. | ||
|
||
**Note**: When GraphQL Engine is running in a Docker container, `localhost` will | ||
point to the containers local interface, not the host's interface. You might | ||
have to use the host's docker host IP or a specific DNS label based on your OS. |
22 changes: 22 additions & 0 deletions
22
community/boilerplates/graphql-servers/nodejs-apollo/package.json
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,22 @@ | ||
{ | ||
"name": "nodejs-apollo-gql-server", | ||
"version": "1.0.0", | ||
"description": "A GraphQL server boilerplate written in NodeJS using and Apollo Server", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Hasura", | ||
"license": "MIT", | ||
"dependencies": { | ||
"apollo-server": "^2.2.1", | ||
"graphql": "^14.0.2", | ||
"graphql-tools": "^4.0.3" | ||
}, | ||
"devDependencies": { | ||
"esm": "^3.0.84" | ||
}, | ||
"scripts": { | ||
"start": "node -r esm server.js" | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
community/boilerplates/graphql-servers/nodejs-apollo/server.js
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,50 @@ | ||
const { ApolloServer } = require('apollo-server'); | ||
const { makeExecutableSchema } = require('graphql-tools'); | ||
|
||
const port = process.env.PORT || 3000; | ||
|
||
let count = 0; | ||
|
||
const typeDefs = ` | ||
type Query { | ||
hello: String! | ||
count: Int! | ||
} | ||
type Mutation { | ||
increment_counter: count_mutation_response! | ||
} | ||
type count_mutation_response { | ||
new_count: Int! | ||
} | ||
`; | ||
|
||
const resolvers = { | ||
Query: { | ||
hello: () => { | ||
return "Hello World!" | ||
}, | ||
count: () => { | ||
return count; | ||
} | ||
}, | ||
Mutation: { | ||
increment_counter: () => { | ||
return { new_count: ++count } | ||
} | ||
} | ||
}; | ||
|
||
const schema = makeExecutableSchema({ | ||
typeDefs, | ||
resolvers | ||
}); | ||
|
||
const server = new ApolloServer({ | ||
schema | ||
}); | ||
|
||
server.listen({ port }).then(({url}) => { | ||
console.log(`GraphQL server running at ${url}`); | ||
}); |
2 changes: 2 additions & 0 deletions
2
community/boilerplates/graphql-servers/nodejs-express/.gitignore
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 @@ | ||
node_modules | ||
package-lock.json |
11 changes: 11 additions & 0 deletions
11
community/boilerplates/graphql-servers/nodejs-express/Dockerfile
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 @@ | ||
FROM node:8 | ||
|
||
WORKDIR /server | ||
|
||
COPY ./package.json /server/ | ||
|
||
RUN npm install | ||
|
||
COPY . /server/ | ||
|
||
CMD ["npm", "start"] |
57 changes: 57 additions & 0 deletions
57
community/boilerplates/graphql-servers/nodejs-express/README.md
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,57 @@ | ||
# GraphQL server using NodeJS-Express | ||
|
||
A boilerplate Python GraphQL Server using NodeJS-Express using the official [graphql-js](https://graphql.github.io/graphql-js/running-an-express-graphql-server/) library. | ||
|
||
## Deploying | ||
|
||
Clone the repo: | ||
|
||
```bash | ||
git clone https://github.com/hasura/graphql-engine | ||
cd graphql-engine/community/boilerplates/graphql-servers/nodejs-express | ||
``` | ||
|
||
### Using Zeit Now | ||
|
||
Install the [Zeit Now](https://zeit.co/now) CLI: | ||
|
||
```bash | ||
npm install -g now | ||
``` | ||
|
||
Deploy the server: | ||
```bash | ||
now | ||
``` | ||
|
||
Get the URL and make a sample query: | ||
```bash | ||
curl https://app-name-something.now.sh/graphql \ | ||
-H 'Content-Type:application/json' \ | ||
-d'{"query":"{ hello }"}' | ||
|
||
{"data":{"hello":"Hello World!"}} | ||
``` | ||
|
||
You can also visit the `/graphql` endpoint of the now url to open GraphiQL. | ||
|
||
## Running locally | ||
Running the server locally: | ||
|
||
```bash | ||
npm install | ||
npm start | ||
``` | ||
|
||
Running the server using Docker: | ||
|
||
```bash | ||
docker build -t nodejs-express-graphql . | ||
docker run -p 4000:4000 nodejs-express-graphql | ||
``` | ||
|
||
GraphQL endpoint will be `http://localhost:4000/graphql`. | ||
|
||
**Note**: When GraphQL Engine is running in a Docker container, `localhost` will | ||
point to the containers local interface, not the host's interface. You might | ||
have to use the host's docker host IP or a specific DNS label based on your OS. |
3 changes: 3 additions & 0 deletions
3
community/boilerplates/graphql-servers/nodejs-express/now.json
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 @@ | ||
{ | ||
"version": 1 | ||
} |
20 changes: 20 additions & 0 deletions
20
community/boilerplates/graphql-servers/nodejs-express/package.json
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,20 @@ | ||
{ | ||
"name": "nodejs-express-gql-server", | ||
"version": "1.0.0", | ||
"description": "A GraphQL server boilerplate for NodeJS-Express using graphql-js library", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node -r esm server.js" | ||
}, | ||
"author": "Hasura", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.16.4", | ||
"express-graphql": "^0.7.1", | ||
"graphql": "^14.0.2" | ||
}, | ||
"devDependencies": { | ||
"esm": "^3.0.84" | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
community/boilerplates/graphql-servers/nodejs-express/server.js
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,44 @@ | ||
const express = require('express'); | ||
const graphqlHTTP = require('express-graphql'); | ||
const { buildSchema } = require('graphql'); | ||
|
||
let count = 0; | ||
const port = process.env.port || 3000; | ||
|
||
// Construct a schema, using GraphQL schema language | ||
const schema = buildSchema(` | ||
type Query { | ||
hello: String! | ||
count: Int! | ||
} | ||
type Mutation { | ||
increment_counter: count_mutation_response! | ||
} | ||
type count_mutation_response { | ||
new_count: Int! | ||
} | ||
`); | ||
|
||
// The root provides a resolver function for each API endpoint | ||
const root = { | ||
hello: () => { | ||
return 'Hello world!'; | ||
}, | ||
count: () => { | ||
return count; | ||
}, | ||
increment_counter: () => { | ||
return { new_count: ++count } | ||
} | ||
}; | ||
|
||
var app = express(); | ||
app.use('/graphql', graphqlHTTP({ | ||
schema: schema, | ||
rootValue: root, | ||
graphiql: true, | ||
})); | ||
app.listen(port); | ||
console.log(`Running a GraphQL API server at localhost:${port}/graphql`); |
Oops, something went wrong.