Skip to content

Commit

Permalink
Merge 0.6.0 -> 0.6.1
Browse files Browse the repository at this point in the history
Merge commit '826cba3b76e87dbd25a01db5150f89624adaab32' into sogko/master

* commit '826cba3b76e87dbd25a01db5150f89624adaab32':
  0.6.1
  Fix tests for node v0.10, widen test matrix
  Fix test assertions for validation test when using custom TypeInfo (graphql#395)
  Removes depencency on babel-runtime.
  Upgrade to Flow v0.28.
  More specific return types from methods in Schema
  Only type Scalar config rather than Scalar type, improve schema builder types
  Introduce formal definition of "Thunk" to aid in fixing more issues uncovered by Flow v0.28
  Additional flow issues corrected in anticipation of Flow v0.28
  Fix some flow issues in anticipation of Flow v0.28
  export type InputObjectConfigFieldMapThunk (graphql#411)
  Variable naming follow-up to path generation
  Errors thrown from resolvers have the execution path (graphql#396)
  Update all dependencies, include flow-specific lint handling
  Revert "Update babel-cli and flow-bin package references" (graphql#403)
  move babel config to the babelrc (graphql#399)
  Update babel-cli and flow-bin package references (graphql#388)
  Fix typo (graphql#387)
  • Loading branch information
sogko committed Jan 27, 2017
2 parents 2e619ab + 826cba3 commit ff9fa78
Show file tree
Hide file tree
Showing 35 changed files with 686 additions and 289 deletions.
25 changes: 25 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"plugins": [
"syntax-async-functions",
"transform-class-properties",
"transform-flow-strip-types",
"transform-object-rest-spread",
"transform-es2015-template-literals",
"transform-es2015-literals",
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
["transform-es2015-classes", {loose: true}],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
"transform-es2015-duplicate-keys",
"transform-es2015-computed-properties",
"check-es2015-constants",
["transform-es2015-spread", {loose: true}],
"transform-es2015-parameters",
["transform-es2015-destructuring", {loose: true}],
"transform-es2015-block-scoping",
"transform-es2015-modules-commonjs",
"transform-regenerator",
]
}
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"parser": "babel-eslint",

"plugins": [
"babel"
"babel",
"flowtype",
"flow-vars"
],

"env": {
Expand Down Expand Up @@ -44,6 +46,11 @@
"array-bracket-spacing": 0,
"generator-star-spacing": 0,

"flowtype/space-after-type-colon": [2, "always"],
"flowtype/space-before-type-colon": [2, "never"],
"flow-vars/define-flow-type": 2,
"flow-vars/use-flow-type": 2,

"arrow-spacing": 2,
"block-scoped-var": 0,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
Expand Down Expand Up @@ -155,7 +162,7 @@
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 0,
"no-sequences": 2,
"no-sequences": 0,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.idea
npm-debug.log

.babelrc
CONTRIBUTING.md
node_modules
coverage
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: node_js

node_js:
- "stable"
- "6"
- "5"
- "4"
- "iojs"
- "0.12"
Expand Down
58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql",
"version": "0.6.0",
"version": "0.6.1",
"description": "A Query Language and Runtime which can target any service.",
"contributors": [
"Lee Byron <lee@leebyron.com> (http://leebyron.com/)",
Expand All @@ -20,19 +20,6 @@
"options": {
"mocha": "--require ./resources/mocha-bootload --check-leaks --full-trace src/**/__tests__/**/*-test.js"
},
"babel": {
"presets": [
"es2015"
],
"plugins": [
"syntax-async-functions",
"transform-class-properties",
"transform-flow-strip-types",
"transform-object-rest-spread",
"transform-regenerator",
"transform-runtime"
]
},
"scripts": {
"test": "npm run lint && npm run check && npm run testonly",
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
Expand All @@ -47,27 +34,40 @@
"preversion": ". ./resources/checkgit.sh && npm test",
"prepublish": ". ./resources/prepublish.sh"
},
"dependencies": {
"babel-runtime": ">=6.0.0"
},
"devDependencies": {
"babel-cli": "6.6.5",
"babel-eslint": "6.0.2",
"babel-plugin-syntax-async-functions": "6.5.0",
"babel-plugin-transform-class-properties": "6.6.0",
"babel-plugin-transform-flow-strip-types": "6.7.0",
"babel-plugin-transform-object-rest-spread": "6.6.5",
"babel-plugin-transform-regenerator": "6.6.5",
"babel-plugin-transform-runtime": "6.6.0",
"babel-preset-es2015": "6.6.0",
"babel-cli": "6.10.1",
"babel-eslint": "6.1.0",
"babel-plugin-check-es2015-constants": "6.8.0",
"babel-plugin-syntax-async-functions": "6.8.0",
"babel-plugin-transform-class-properties": "6.10.2",
"babel-plugin-transform-es2015-arrow-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoped-functions": "6.8.0",
"babel-plugin-transform-es2015-block-scoping": "6.10.1",
"babel-plugin-transform-es2015-classes": "6.9.0",
"babel-plugin-transform-es2015-computed-properties": "6.8.0",
"babel-plugin-transform-es2015-destructuring": "6.9.0",
"babel-plugin-transform-es2015-duplicate-keys": "6.8.0",
"babel-plugin-transform-es2015-function-name": "6.9.0",
"babel-plugin-transform-es2015-literals": "6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "6.10.3",
"babel-plugin-transform-es2015-object-super": "6.8.0",
"babel-plugin-transform-es2015-parameters": "6.9.0",
"babel-plugin-transform-es2015-shorthand-properties": "6.8.0",
"babel-plugin-transform-es2015-spread": "6.8.0",
"babel-plugin-transform-es2015-template-literals": "6.8.0",
"babel-plugin-transform-flow-strip-types": "6.8.0",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-plugin-transform-regenerator": "6.9.0",
"chai": "3.5.0",
"chai-subset": "1.2.2",
"coveralls": "2.11.9",
"eslint": "2.7.0",
"eslint": "2.11.1",
"eslint-plugin-babel": "3.2.0",
"flow-bin": "0.22.1",
"eslint-plugin-flow-vars": "0.4.0",
"eslint-plugin-flowtype": "2.2.7",
"flow-bin": "0.28.0",
"isparta": "4.0.0",
"mocha": "2.4.5",
"mocha": "2.5.3",
"sane": "1.3.4"
}
}
5 changes: 4 additions & 1 deletion resources/prepublish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ babel src --ignore __tests__ --out-dir ./
# Ensure a vanilla package.json before deploying so other tools do not interpret
# The built output as requiring any further transformation.
node -e "var package = require('./package.json'); \
delete package.babel; delete package.scripts; delete package.options; \
delete package.babel; \
delete package.scripts; \
delete package.options; \
delete package.devDependencies; \
require('fs').writeFileSync('package.json', JSON.stringify(package));"
15 changes: 15 additions & 0 deletions src/__tests__/starWarsIntrospection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ describe('Star Wars Introspection Tests', () => {
kind: 'LIST'
}
},
{
name: 'secretBackstory',
type: {
name: 'String',
kind: 'SCALAR'
}
},
{
name: 'primaryFunction',
type: {
Expand Down Expand Up @@ -284,6 +291,14 @@ describe('Star Wars Introspection Tests', () => {
}
}
},
{
name: 'secretBackstory',
type: {
name: 'String',
kind: 'SCALAR',
ofType: null
}
},
{
name: 'primaryFunction',
type: {
Expand Down
164 changes: 164 additions & 0 deletions src/__tests__/starWarsQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { StarWarsSchema } from './starWarsSchema.js';
import { graphql } from '../graphql';
import {
GraphQLObjectType,
GraphQLNonNull,
GraphQLSchema,
GraphQLString,
} from '../type';

// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */
Expand Down Expand Up @@ -364,4 +370,162 @@ describe('Star Wars Query Tests', () => {
expect(result).to.deep.equal({ data: expected });
});
});

describe('Reporting errors raised in resolvers', () => {
it('Correctly reports error on accessing secretBackstory', async () => {
const query = `
query HeroNameQuery {
hero {
name
secretBackstory
}
}
`;
const expected = {
hero: {
name: 'R2-D2',
secretBackstory: null
}
};
const expectedErrors = [ 'secretBackstory is secret.' ];
const result = await graphql(StarWarsSchema, query);
expect(result.data).to.deep.equal(expected);
expect(result.errors.map(e => e.message)).to.deep.equal(expectedErrors);
expect(
result.errors.map(e => e.path)).to.deep.equal(
[ [ 'hero', 'secretBackstory' ] ]);
});

it('Correctly reports error on accessing secretBackstory in a list', async () => {
const query = `
query HeroNameQuery {
hero {
name
friends {
name
secretBackstory
}
}
}
`;
const expected = {
hero: {
name: 'R2-D2',
friends: [
{
name: 'Luke Skywalker',
secretBackstory: null,
},
{
name: 'Han Solo',
secretBackstory: null,
},
{
name: 'Leia Organa',
secretBackstory: null,
},
]
}
};
const expectedErrors = [
'secretBackstory is secret.',
'secretBackstory is secret.',
'secretBackstory is secret.',
];
const result = await graphql(StarWarsSchema, query);
expect(result.data).to.deep.equal(expected);
expect(result.errors.map(e => e.message)).to.deep.equal(expectedErrors);
expect(
result.errors.map(e => e.path)
).to.deep.equal(
[
[ 'hero', 'friends', 0, 'secretBackstory' ],
[ 'hero', 'friends', 1, 'secretBackstory' ],
[ 'hero', 'friends', 2, 'secretBackstory' ],
]);
});

it('Correctly reports error on accessing through an alias', async () => {
const query = `
query HeroNameQuery {
mainHero: hero {
name
story: secretBackstory
}
}
`;
const expected = {
mainHero: {
name: 'R2-D2',
story: null,
}
};
const expectedErrors = [
'secretBackstory is secret.',
];
const result = await graphql(StarWarsSchema, query);
expect(result.data).to.deep.equal(expected);
expect(result.errors.map(e => e.message)).to.deep.equal(expectedErrors);
expect(
result.errors.map(e => e.path)
).to.deep.equal([ [ 'mainHero', 'story' ] ]);
});

it('Full response path is included when fields are non-nullable', async () => {
const A = new GraphQLObjectType({
name: 'A',
fields: () => ({
nullableA: {
type: A,
resolve: () => ({}),
},
nonNullA: {
type: new GraphQLNonNull(A),
resolve: () => ({}),
},
throws: {
type: new GraphQLNonNull(GraphQLString),
resolve: () => { throw new Error('Catch me if you can'); },
},
}),
});
const queryType = new GraphQLObjectType({
name: 'query',
fields: () => ({
nullableA: {
type: A,
resolve: () => ({})
}
}),
});
const schema = new GraphQLSchema({
query: queryType,
});

const query = `
query {
nullableA {
nullableA {
nonNullA {
nonNullA {
throws
}
}
}
}
}
`;

const result = await graphql(schema, query);
const expected = {
nullableA: {
nullableA: null
}
};
expect(result.data).to.deep.equal(expected);
expect(
result.errors.map(e => e.path)).to.deep.equal(
[ [ 'nullableA', 'nullableA', 'nonNullA', 'nonNullA', 'throws' ] ]);
});
});
});
Loading

0 comments on commit ff9fa78

Please sign in to comment.