这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
e3de880
basic proxying to remote graphql server
ecthiender Oct 15, 2018
86da7e0
use updated graphql-parser
ecthiender Oct 16, 2018
728d0b3
basic working of custom resolver with introspection
ecthiender Oct 22, 2018
9c6d485
proper working on schema stitching
ecthiender Oct 25, 2018
993888e
add migration support from 3 to 4
ecthiender Oct 26, 2018
ce0aacb
first version of schema stitching with multiple remotes
ecthiender Oct 31, 2018
d5d6047
Merge branch 'master' of hasura/graphql-engine into schema-stitching
ecthiender Oct 31, 2018
72c3dd8
Add scaffolding
karthikvt26 Oct 31, 2018
3411de4
refactor new code to use the new types
ecthiender Oct 31, 2018
4ff209e
add Pipfile to gitignore
ecthiender Oct 31, 2018
e1da62e
add delete custom resolver query
ecthiender Oct 31, 2018
72e6b8d
WIP
surendran82 Oct 31, 2018
90c95bd
Merge branch 'master' into schema-stitching
shahidhk Oct 31, 2018
b85fc89
track table now checks for conflicting nodes in graphql schema
ecthiender Oct 31, 2018
8c75376
refactor graphql validate function
ecthiender Oct 31, 2018
3f5b94f
UI made for custom resolver
surendran82 Nov 1, 2018
7d7663a
Add dummy resolver reducer
karthikvt26 Nov 1, 2018
d1e4d70
Merge branch 'schema-stitch-console' of github.com:karthikvt26/graphq…
karthikvt26 Nov 1, 2018
e93b2c4
Radio button options fix
surendran82 Nov 1, 2018
a30ebd0
Add basic reducer for listing custom resolvers
karthikvt26 Nov 1, 2018
a6ab3a9
Merge branch 'schema-stitch-console' of github.com:karthikvt26/graphq…
karthikvt26 Nov 1, 2018
941545d
add custom_resolver to default tracked tables
ecthiender Nov 1, 2018
c3160a2
Header section close icon added
surendran82 Nov 1, 2018
197310d
Add basic add/delete resolver functionality without headers
karthikvt26 Nov 1, 2018
597ec58
Merge branch 'schema-stitch-console' of github.com:karthikvt26/graphq…
karthikvt26 Nov 1, 2018
f041431
add export metadata, replace metadata for custom resolvers
ecthiender Nov 2, 2018
0104a46
migrate metadata from 3 to 4
ecthiender Nov 2, 2018
e76ef2c
Basic integration done
karthikvt26 Nov 2, 2018
9082c63
Add custom_resolver:[] into the metadata byte array
karthikvt26 Nov 2, 2018
3b9ba79
Add custom_resolver:[] into the empty metadata byte array
karthikvt26 Nov 2, 2018
6b57c19
Fix order of keys in metadata
karthikvt26 Nov 2, 2018
55d8d60
Add landing page image
karthikvt26 Nov 2, 2018
9f19bb3
Fix few issues
karthikvt26 Nov 2, 2018
d6ab893
fix bug with remote schema when no hasura tables exist
ecthiender Nov 2, 2018
625ed5d
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 2, 2018
e5dfc9c
fix a bug in deleting custom resolver
ecthiender Nov 3, 2018
4ece05d
Changed modify to delete -> insert, need to change this to one query …
karthikvt26 Nov 3, 2018
d0add62
Merge branch 'schema-stitch-console' into schema-stitching
karthikvt26 Nov 3, 2018
abc4514
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 3, 2018
e4fdfeb
schema stitching docs WIP
rikinsk Nov 4, 2018
91a6a3a
Update image to google storage url
karthikvt26 Nov 5, 2018
be3ee30
mutation can be optional in remote graphql server
ecthiender Nov 5, 2018
165c4af
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 5, 2018
138bd9d
Few ui fixes, add breadcrumb
karthikvt26 Nov 5, 2018
6d5f18c
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 5, 2018
ec3ce8a
Change refresh schema to button
karthikvt26 Nov 5, 2018
c37d126
send user variable headers to remote graphql server
ecthiender Nov 6, 2018
b8d327f
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 6, 2018
f06a9d1
adds content for schema stitching
dsandip Nov 7, 2018
2a94777
examples queries added to content
dsandip Nov 7, 2018
c8c9503
fixed typo
dsandip Nov 7, 2018
79ea6f3
Change header/url input field into a custom controlled component base…
karthikvt26 Nov 8, 2018
4883844
intermediate commit to save work
ecthiender Nov 8, 2018
c2cb6c5
v1 update ux
karthikvt26 Nov 8, 2018
ceefe53
Trim schema name
karthikvt26 Nov 8, 2018
4f064fc
put GCtxMap also inside SchemaCache as state
ecthiender Nov 8, 2018
22063c0
refactor module GraphQL.Schema
ecthiender Nov 8, 2018
31cfc37
forward config headers to the remote server
ecthiender Nov 8, 2018
a2c646a
only queries with hasura nodes can be explained
ecthiender Nov 8, 2018
cb005c4
change {add_custom_resolver, delete_custom_resolver} => {add_remote_s…
ecthiender Nov 8, 2018
d4f33f4
change table schema for remote schemas metadata
ecthiender Nov 8, 2018
3e27703
rename modules
ecthiender Nov 8, 2018
d053a45
refresh gctxMap in schemacache in track/untrack table and run sql
ecthiender Nov 8, 2018
be4fe90
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 8, 2018
9f3fd83
fix cli metadata tests
ecthiender Nov 8, 2018
0a1b6ad
Merge branch 'master' of github.com:hasura/graphql-engine into schema…
ecthiender Nov 8, 2018
7a749a4
rename stitched schemas to remote schemas
shahidhk Nov 9, 2018
2021a55
revert last change
shahidhk Nov 9, 2018
3aaf272
Change api call to new server api, add data-test for all user input c…
karthikvt26 Nov 9, 2018
208ca8b
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 9, 2018
cb227f2
add python-flask graphql server boilerplate
shahidhk Nov 9, 2018
501ed9e
Merge branch 'master' into graphql-server-boilerplates
shahidhk Nov 9, 2018
d223dd0
modifies docs for remote schemas
dsandip Nov 11, 2018
160a81f
small refactor
ecthiender Nov 12, 2018
76d3255
WIP tests for schema-stitching
karthikvt26 Nov 12, 2018
3452d94
add a default gCtx for any role for remote schemas
ecthiender Nov 12, 2018
3ab74d5
forward headers from client
ecthiender Nov 12, 2018
cf1e08a
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 12, 2018
8d8e981
Add forward client header checkbox
karthikvt26 Nov 12, 2018
de782b8
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 12, 2018
c40e577
Merge branch 'schema-stitching-defaultgctx' into schema-stitching
ecthiender Nov 13, 2018
b5eee3f
Enable all tests for remote schemas
karthikvt26 Nov 13, 2018
6faa7ee
Update text, add more tests
karthikvt26 Nov 13, 2018
38e4e07
fix a bug with building schema cache again
ecthiender Nov 13, 2018
ac5c01f
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 13, 2018
b823cca
add nodeJS GraphQL server boilerplate
wawhal Nov 13, 2018
43305cf
Merge branch 'master' into graphql-server-boilerplates
shahidhk Nov 13, 2018
45fabf5
Add pattern to validate schema alias input, update test graphql url
karthikvt26 Nov 13, 2018
ca24ea5
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 13, 2018
975dc0c
Fix migration file generated for delete remote schema
karthikvt26 Nov 13, 2018
90db553
Change test url to heroku for now
karthikvt26 Nov 13, 2018
cb13615
replaces screenshot and adds minor edits
dsandip Nov 13, 2018
be4d4f1
remote queries over websocket protocol
ecthiender Nov 13, 2018
7a8f9a8
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 13, 2018
4b9b9bd
check for type conflicts as well in remote schema
ecthiender Nov 14, 2018
cf9f088
Merge branch 'master' of github.com:hasura/graphql-engine into schema…
ecthiender Nov 14, 2018
7cac151
minor edits
dsandip Nov 14, 2018
3dac033
ignore hasura query/mutation roots for checking type conflicts
ecthiender Nov 14, 2018
26aa2a0
modifies structure for remote schema docs
dsandip Nov 15, 2018
065a2c0
reformat custom biz logic docs pages
rikinsk Nov 15, 2018
2f5e3f7
Merge branch 'schema-stitching-docs' into schema-stitching
rikinsk Nov 15, 2018
3dbb35f
fix typo in docs
rikinsk Nov 15, 2018
cfbff5a
incorporate review changes
ecthiender Nov 15, 2018
32f9610
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 15, 2018
841bc9b
Merge branch 'master' of github.com:hasura/graphql-engine into schema…
ecthiender Nov 15, 2018
5d6258c
change api according to new spec
ecthiender Nov 16, 2018
acbc93a
Update create/remove schema api as per server change
karthikvt26 Nov 16, 2018
f917e17
fix bug in merging mutation roots
ecthiender Nov 16, 2018
cb50824
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 16, 2018
6754780
throw appropriate for subscription to remote server
ecthiender Nov 16, 2018
f70c171
modifies title for biz logic docs and fixes typo
dsandip Nov 16, 2018
5987fcb
take port from env and default to 3000
wawhal Nov 19, 2018
5f42727
take port from env in node apollo boilerplate
wawhal Nov 19, 2018
7285c6a
Update community/boilerplates/graphql-servers/nodejs-express/server.js
shahidhk Nov 19, 2018
3345622
Merge pull request #1 from wawhal/gql-server-bplates-port3000
shahidhk Nov 19, 2018
143df31
Merge branch 'master' into graphql-server-boilerplates
shahidhk Nov 19, 2018
c985749
move remote schema page to top level in docs
rikinsk Nov 19, 2018
1f29e45
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
rikinsk Nov 19, 2018
ea15d39
add now.json
shark-h Nov 19, 2018
ba786ed
Merge pull request #2 from shark-h/now-json-fix
shahidhk Nov 19, 2018
43beffa
add vscode to gitignore
shahidhk Nov 20, 2018
0df3e74
add mutation to boilerplate and add now.json
shahidhk Nov 20, 2018
f74cf35
Merge branch 'master' of github.com:hasura/graphql-engine into schema…
ecthiender Nov 20, 2018
26c07d4
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 20, 2018
c5ff6f9
update readme
shahidhk Nov 20, 2018
b1dc56b
Merge branch 'graphql-server-boilerplates' into schema-stitching
shahidhk Nov 20, 2018
ddbbe8d
add remote schemas content in README
dsandip Nov 20, 2018
738732f
add preliminary tests for schema stitching
ecthiender Nov 20, 2018
f6caf79
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 20, 2018
f9b53b5
Fix typo
karthikvt26 Nov 20, 2018
c21ae3d
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 20, 2018
09afd44
add demo video for remote schemas
dsandip Nov 20, 2018
bbd9d8b
fix typo
dsandip Nov 20, 2018
13708d7
fix internal link
dsandip Nov 21, 2018
2693b6f
Merge branch 'remote-schemas-readme-update' into schema-stitching
dsandip Nov 21, 2018
6dd4174
update graphql server boilerplates readme
shahidhk Nov 21, 2018
d493899
update arch diagram and the markdown
shahidhk Nov 21, 2018
8f41578
update arch image
shahidhk Nov 21, 2018
96aaebc
update readmes
shahidhk Nov 21, 2018
f10e3aa
add minor edits to remote-schemas.md and extend caveat in docs
dsandip Nov 21, 2018
b04f90e
add deprecation notice for custom resolvers
shahidhk Nov 21, 2018
f345776
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
shahidhk Nov 21, 2018
63a5885
add deprecated to custom resolvers title
shahidhk Nov 21, 2018
36395db
Merge branch 'master' into schema-stitching
shahidhk Nov 21, 2018
dcfe83a
edit deprecation disclaimer in custom resolvers README
dsandip Nov 21, 2018
c4c47e0
cleanup tests
ecthiender Nov 21, 2018
1ecbe07
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 21, 2018
d2b1d32
add more details to caveats for current limitations
dsandip Nov 21, 2018
583d548
minor refactor
ecthiender Nov 21, 2018
f5f8fd3
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
ecthiender Nov 21, 2018
412bb25
move parsing introspection query result into graphql-engine
ecthiender Nov 22, 2018
0217b05
update graphql-parser dependency to the master
ecthiender Nov 23, 2018
b2a7c18
Merge branch 'master' of github.com:hasura/graphql-engine into schema…
ecthiender Nov 23, 2018
185c39b
hides business-logic section; improves remote-schemas/index
coco98 Nov 23, 2018
e1523cd
Adds remote-schemas-arch diagram
coco98 Nov 23, 2018
ee14263
Minor docs change.
coco98 Nov 23, 2018
a585313
modifies disclaimer in custom resolvers readme
dsandip Nov 23, 2018
dd6fbad
minor changes to docs
ecthiender Nov 23, 2018
a89eecc
Merge branch 'master' into schema-stitching
ecthiender Nov 23, 2018
964bba0
improve header docs for remote schemas
ecthiender Nov 23, 2018
ca4a3fb
modify arch section in README
dsandip Nov 23, 2018
4f8d874
Change text, add tooltip for additional header section
karthikvt26 Nov 23, 2018
dce49f9
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
karthikvt26 Nov 23, 2018
b434a85
Merge branch 'schema-stitching' of github.com:ecthiender/graphql-engi…
dsandip Nov 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
*.DS_Store
.tern-project
test-server-output
.vscode
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://twitter.com/intent/follow?screen_name=HasuraHQ"><img src="https://img.shields.io/badge/Follow-HasuraHQ-blue.svg?style=flat&logo=twitter"></a>
<a href="https://eepurl.com/dBUfJ5"><img src="https://img.shields.io/badge/newsletter-subscribe-yellow.svg?style=flat"></a>

Hasura GraphQL Engine is a blazing-fast GraphQL server that gives you **instant, realtime GraphQL APIs over Postgres**, with [**webhook triggers**](event-triggers.md) on database events for asynchronous business logic.
Hasura GraphQL Engine is a blazing-fast GraphQL server that gives you **instant, realtime GraphQL APIs over Postgres**, with [**webhook triggers**](event-triggers.md) on database events, and [**remote schemas**](remote-schemas.md) for business logic.

Hasura helps you build GraphQL apps backed by Postgres or incrementally move to GraphQL for existing applications using Postgres.

Expand All @@ -28,6 +28,7 @@ Read more at [hasura.io](https://hasura.io) and the [docs](https://docs.hasura.i

* **Make powerful queries**: Built-in filtering, pagination, pattern search, bulk insert, update, delete mutations
* **Realtime**: Convert any GraphQL query to a live query by using subscriptions
* **Merge remote schemas**: Access custom GraphQL schemas for business logic via a single GraphQL Engine endpoint. [**Read more**](remote-schemas.md).
* **Trigger webhooks or serverless functions**: On Postgres insert/update/delete events ([read more](event-triggers.md))
* **Works with existing, live databases**: Point it to an existing Postgres database to instantly get a ready-to-use GraphQL API
* **Fine-grained access control**: Dynamic access control that integrates with your auth system (eg: auth0, firebase-auth)
Expand All @@ -47,7 +48,7 @@ Read more at [https://hasura.io](https://hasura.io) and the [docs](https://docs.
- [Architecture](#architecture)
- [Client-side tooling](#client-side-tooling)
- [Add business logic](#add-business-logic)
- [Custom resolvers](#custom-resolvers)
- [Remote schemas](#remote-schemas)
- [Trigger webhooks on database events](#trigger-webhooks-on-database-events)
- [Demos](#demos)
- [Realtime applications](#realtime-applications)
Expand Down Expand Up @@ -87,7 +88,7 @@ guides](https://docs.hasura.io/1.0/graphql/manual/getting-started/index.html) or

The Hasura GraphQL Engine fronts a Postgres database instance and can accept GraphQL requests from your client apps. It can be configured to work with your existing auth system and can handle access control using field-level rules with dynamic variables from your auth system.

You can also place the engine behind a central GraphQL proxy that fronts multiple GraphQL APIs via schema stitching.
You can also merge remote GraphQL schemas and provide a unified GraphQL API.

![Hasura GraphQL Engine architecture](assets/hasura-arch.svg)

Expand All @@ -97,18 +98,22 @@ Hasura works with any GraphQL client. We recommend using [Apollo Client](https:/

## Add business logic

### Custom resolvers
GraphQL Engine provides easy-to-reason, scalable and performant methods for adding custom business logic to your backend:

Add custom resolvers in addition to Hasura GraphQL engine. Ideal for delegating
to HTTP APIs, making direct calls to another data-source or writing business
logic in code - [read more](community/boilerplates/custom-resolvers).
### Remote schemas

Add custom resolvers in a remote schema in addition to Hasura's Postgres-based GraphQL schema. Ideal for use-cases like implementing a payment API, or querying data that is not in your database - [read more](remote-schemas.md).

### Trigger webhooks on database events

Add asynchronous business logic that is triggered based on database events.
Ideal for notifications, data-pipelines from Postgres or asynchronous
processing - [read more](event-triggers.md).

### Derived data or data transformations

Transform data in Postgres or run business logic on it to derive another dataset that can be queried using GraphQL Engine - [read more](https://docs.hasura.io/1.0/graphql/manual/business-logic/index.html).

## Demos

Check out all the example applications in the
Expand Down
2 changes: 1 addition & 1 deletion assets/hasura-arch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/remote-schemas-arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions cli/commands/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var ravenVersions = []mt.Version{

var testMetadata = map[string][]byte{
"metadata": []byte(`query_templates: []
remote_schemas: []
tables:
- array_relationships: []
delete_permissions: []
Expand All @@ -40,6 +41,7 @@ tables:
update_permissions: []
`),
"empty-metadata": []byte(`query_templates: []
remote_schemas: []
tables: []
`),
}
Expand Down
5 changes: 4 additions & 1 deletion community/boilerplates/custom-resolvers/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# GraphQL Custom Resolver Example

This is a simple example of using a custom resolver with Hasura's GraphQL API.
> **NOTE**: now merge [Remote Schemas](../../../remote-schemas.md) from [GraphQL servers](../graphql-servers) using Hasura
> - Boilerplates for custom GraphQL servers have been moved [here](../graphql-servers). Also, a recently released feature removes the need for an external GraphQL gateway by letting you merge remote schemas in GraphQL Engine itself - [read more](../../../remote-schemas.md) (*Please check caveats for current limitations in the feature*).
> - Once schemas have been merged in GraphQL Engine, Hasura proxies requests to remote GraphQL servers.
> - Adding another layer in front of GraphQL Engine impacts performance by as much as **4X**, due the serialization-deserialization overhead. Using an external GraphQL gateway is recommended only if your use case is blocked on any of the current limitations.

## Motivation

Expand Down
15 changes: 15 additions & 0 deletions community/boilerplates/graphql-servers/README.md
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)
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 community/boilerplates/graphql-servers/nodejs-apollo/Dockerfile
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 community/boilerplates/graphql-servers/nodejs-apollo/README.md
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 community/boilerplates/graphql-servers/nodejs-apollo/package.json
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 community/boilerplates/graphql-servers/nodejs-apollo/server.js
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}`);
});
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 community/boilerplates/graphql-servers/nodejs-express/Dockerfile
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 community/boilerplates/graphql-servers/nodejs-express/README.md
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": 1
}
20 changes: 20 additions & 0 deletions community/boilerplates/graphql-servers/nodejs-express/package.json
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 community/boilerplates/graphql-servers/nodejs-express/server.js
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`);
Loading