Skip to content

Commit b6b54d8

Browse files
authored
feat: upgrade to 1.x format (#5)
* feat: 1.x refactor * feat: update getting started instructions * ci: change Node targets
1 parent 2037fe3 commit b6b54d8

17 files changed

+715
-579
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ cache:
44
directories:
55
- node_modules
66
node_js:
7-
- "6"
8-
- "7"
9-
- "8"
7+
- 6
8+
- 8
9+
- 9
1010
notifications:
1111
email: false
1212
before_script:

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<img src="https://gramps-graphql.github.io/gramps-express/assets/img/gramps-banner.png" alt="GrAMPS · An easier way to manage the data sources powering your GraphQL server" width="450">
1+
<a href="https://gramps.js.org/"><img src="https://gramps.js.org/assets/img/gramps-banner.png" alt="GrAMPS · An easier way to manage the data sources powering your GraphQL server" width="450"></a>
22

33
# GrAMPS GraphQL Data Source Base
44
[![Build Status](https://travis-ci.org/gramps-graphql/data-source-base.svg?branch=master)](https://travis-ci.org/gramps-graphql/data-source-base) [![Maintainability](https://api.codeclimate.com/v1/badges/ac264833fac1fbd1afe0/maintainability)](https://codeclimate.com/github/gramps-graphql/data-source-base/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/ac264833fac1fbd1afe0/test_coverage)](https://codeclimate.com/github/gramps-graphql/data-source-base/test_coverage) [![npm version](https://img.shields.io/npm/v/@gramps/data-source-base.svg?style=flat)](https://www.npmjs.com/package/@gramps/data-source-base) [![Greenkeeper badge](https://badges.greenkeeper.io/gramps-graphql/data-source-base.svg)](https://greenkeeper.io/)
55

66
This is a minimal example and boilerplate for a GrAMPS data source. Inside, you’ll find:
77

8-
- **Connector** — how to access the data source (e.g. a REST API)
9-
- **Model** — methods to retrieve/modify data from the data source (e.g. a
10-
CRUD wrapper)
11-
- **Schema** — description for GraphQL to interpret the data (see the
8+
- **Context** — an object with methods to retrieve/modify data from the data
9+
source (e.g. a CRUD wrapper)
10+
- **Schema** — type definitions for GraphQL to interpret the data (see the
1211
[GraphQL docs on schemas](http://graphql.org/learn/schema/))
1312
- **Resolvers** — functions to map the results of calls to model methods to
1413
the schema
14+
- **Mock Resolvers** — mock functions for offline development
1515

1616
Each file contains a `TODO` comment explaining the changes you’ll need to make to create a working data source.
1717

@@ -32,40 +32,43 @@ To help ensure a reliable, easy-to-maintain data source, this example also inclu
3232
**NOTE:** Replace all instances of `YOUR_DATA_SOURCE_NAME` with the actual name you want to use (e.g. `data-source-companyname-datatype`).
3333

3434
```sh
35-
# Clone the repo
36-
git clone git@github.com:gramps-graphql/data-source-base.git data-source-YOUR_DATA_SOURCE_NAME
35+
# Get a copy of the data source
36+
npx degit gramps-graphql/data-source-base data-source-YOUR_DATA_SOURCE_NAME
3737

3838
# Move into it
3939
cd data-source-YOUR_DATA_SOURCE_NAME/
4040

41-
# Change the remote repo
42-
git remote set-url origin git@github.com:USER_OR_ORG/YOUR_REPO_NAME.git
43-
4441
# IMPORTANT: Make sure to edit the name, description, contributors, and
4542
# repository fields in package.json
4643

4744
# Install dependencies
48-
yarn install
49-
```
45+
yarn
5046

51-
### To Develop with Mock Data
47+
# Start the dev server
48+
yarn dev
49+
```
5250

53-
Start the app with the following command:
51+
You'll see a message with URLs for the GraphQL gateway and the [GraphQL Playground](https://github.com/graphcool/graphql-playground). Open the Playground link (usually http://localhost:8080/playground if you don’t already have something running on port 8080), then run a query:
5452

55-
```sh
56-
# Develop with mock data
57-
yarn mock-data
53+
```graphql
54+
{
55+
getById(id: 123) {
56+
id
57+
name
58+
lucky_numbers
59+
}
60+
}
5861
```
5962

60-
### To Develop with Live Data
63+
### To Develop with Mock Data
6164

62-
Once you’ve got your data source configured to load live data, you can enable live data in development:
65+
Start the app with the following command:
6366

6467
```sh
65-
# Develop with live data
66-
yarn live-data
68+
# Start the gateway with mock data
69+
yarn dev --mock
6770
```
6871

6972
### Notes for Developers
7073

71-
Currently, there is no watch capability (PRs welcome!), so the service needs to be stopped (`control` + `C`) and restarted (`yarn [mock-data|live-data]`) to reflect new changes to the data source.
74+
Currently, there is no watch capability (PRs welcome!), so the service needs to be stopped (`control` + `C`) and restarted (`yarn dev`) to reflect new changes to the data source.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
"prepush": "npm test",
2020
"prebuild": "del-cli ./dist",
2121
"build": "babel src -d dist",
22-
"dev": "gramps --data-source-dir ./",
23-
"mock-data": "npm run dev -- --mock",
24-
"live-data": "npm run dev -- --live",
22+
"dev": "gramps dev --data-source .",
23+
"dev:mock-data": "gramps dev --data-source . --mock",
2524
"lint": "eslint src/",
2625
"test:unit": "cross-env NODE_ENV=test jest --coverage",
2726
"test": "npm run lint --silent && npm run test:unit --silent",
@@ -32,33 +31,34 @@
3231
],
3332
"license": "MIT",
3433
"dependencies": {
35-
"@gramps/gramps-express": "^0.1.3",
36-
"casual": "^1.5.14"
34+
"casual": "^1.5.19"
3735
},
3836
"peerDependencies": {
3937
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0",
4038
"graphql-tools": "^1.2.1 || ^2.5.1"
4139
},
4240
"devDependencies": {
41+
"@gramps/cli": "^1.0.0-beta.4",
42+
"@gramps/gramps": "^1.0.0-beta-7",
4343
"babel-cli": "^6.24.1",
44-
"babel-eslint": "^8.0.1",
44+
"babel-eslint": "^8.0.3",
4545
"babel-jest": "^21.2.0",
4646
"babel-plugin-inline-import": "^2.0.6",
4747
"babel-preset-env": "^1.6.1",
4848
"babel-preset-stage-2": "^6.24.1",
4949
"cross-env": "^5.1.1",
5050
"del-cli": "^1.1.0",
51-
"eslint": "^4.4.1",
51+
"eslint": "^4.13.1",
5252
"eslint-config-airbnb-base": "^12.1.0",
53-
"eslint-config-prettier": "^2.3.0",
54-
"eslint-plugin-import": "^2.7.0",
55-
"eslint-plugin-prettier": "^2.1.2",
53+
"eslint-config-prettier": "^2.9.0",
54+
"eslint-plugin-import": "^2.8.0",
55+
"eslint-plugin-prettier": "^2.4.0",
5656
"graphql": "^0.11.7",
57-
"graphql-tools": "^2.5.1",
57+
"graphql-tools": "^2.13.0",
5858
"husky": "^0.14.3",
5959
"jest": "^21.2.1",
60-
"nodemon": "^1.11.0",
61-
"prettier": "^1.5.3",
60+
"nodemon": "^1.13.3",
61+
"prettier": "^1.9.2",
6262
"semantic-release": "^8.2.0"
6363
},
6464
"jest": {

src/connector.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/context.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
getById: id => ({
3+
id,
4+
name: 'GrAMPS Data Source Base',
5+
lucky_numbers: [1, 2, 3, 5, 8, 13, 21],
6+
}),
7+
};

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import schema from './schema.graphql';
1+
import typeDefs from './schema.graphql';
2+
import context from './context';
23
import resolvers from './resolvers';
3-
import Connector from './connector';
4-
import Model from './model';
4+
import mocks from './mocks';
55

66
/*
77
* For more information on the main data source object, see
88
* https://ibm.biz/graphql-data-source-main
99
*/
1010
export default {
1111
// TODO: Rename the context to describe the data source.
12-
context: 'YourDataSource',
13-
model: new Model({ connector: new Connector() }),
14-
schema,
12+
namespace: 'DataSourceBase',
13+
context,
14+
typeDefs,
1515
resolvers,
16+
mocks,
1617
};

src/mocks.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { MockList } from 'graphql-tools';
2+
import casual from 'casual';
3+
4+
export default {
5+
// TODO: Update to mock all schema fields and types.
6+
PFX_DataSourceBase: () => ({
7+
id: casual.uuid,
8+
name: casual.name,
9+
lucky_numbers: () => new MockList([0, 3]), // casual.array_of_digits(3),
10+
}),
11+
};

src/model.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/resolvers.js

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
1-
import { MockList } from 'graphql-tools';
2-
import casual from 'casual';
3-
4-
/*
5-
* For more information on data source resolvers, see
6-
* https://ibm.biz/graphql-data-source-resolvers
7-
*/
8-
91
export default {
10-
// Queries (where does the data come from?)
11-
queryResolvers: {
2+
Query: {
123
// TODO: Update query resolver name(s) to match schema queries
13-
YourDataSource: (rootValue, { id }, context) =>
14-
new Promise((resolve, reject) => {
15-
// TODO: Update to use the model and call the proper method.
16-
context.YourDataSource
17-
.getById(id)
18-
.then(resolve)
19-
.catch(reject);
20-
}),
4+
getById: (_, { id }, context) =>
5+
// TODO: Update to use the model and call the proper method.
6+
context.getById(id),
217
},
22-
23-
// Data fields (which data from the response goes to which field?)
24-
dataResolvers: {
25-
// TODO: Update to reference the schema type(s) and field(s).
26-
PFX_YourDataSource: {
27-
// If a field isn’t always set, but it shouldn’t break the response, make it nullable.
28-
name: data => data.name || null,
29-
},
30-
},
31-
32-
// Mock data (How can I get real-feeling fake data while working offline?)
33-
mockResolvers: {
34-
// TODO: Update to mock all schema fields and types.
35-
PFX_YourDataSource: () => ({
36-
id: casual.uuid,
37-
name: casual.name,
38-
lucky_numbers: () => new MockList([0, 3]),
39-
}),
8+
// TODO: Update to reference the schema type(s) and field(s).
9+
PFX_DataSourceBase: {
10+
name: data => data.name || null,
4011
},
4112
};

src/schema.graphql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# The query/queries to access data MUST extend the Query type.
2-
extend type Query {
1+
type Query {
32
# TODO: rename and add a description of this query
4-
YourDataSource(
3+
getById(
54
# TODO: Describe this argument
65
id: ID!
7-
): PFX_YourDataSource
6+
): PFX_DataSourceBase
87
}
98

109
# TODO: Choose a unique prefix and rename the type descriptively.
11-
type PFX_YourDataSource {
10+
type PFX_DataSourceBase {
1211
# The unique ID of the thing.
1312
id: ID!
1413
# Describe each field to help people use the data more effectively.

0 commit comments

Comments
 (0)