Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: apollographql/graphql-tag
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.0
Choose a base ref
...
head repository: apollographql/graphql-tag
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.4.0
Choose a head ref
  • 5 commits
  • 4 files changed
  • 2 contributors

Commits on Jun 16, 2017

  1. feat(descriptors): add support for descriptors (#99)

    * feat(descriptors): add support for descriptors
    
    * Improve descriptor test with more assertions
    jamiter authored and jnwng committed Jun 16, 2017
    Copy the full SHA
    78ed906 View commit details
  2. Updating changelog

    jnwng committed Jun 16, 2017
    Copy the full SHA
    3605003 View commit details
  3. 2.3.0

    jnwng committed Jun 16, 2017
    Copy the full SHA
    c5065ef View commit details
  4. Updating Changelog.md

    jnwng committed Jun 16, 2017
    Copy the full SHA
    ae60217 View commit details
  5. 2.4.0

    jnwng committed Jun 16, 2017
    Copy the full SHA
    1151365 View commit details
Showing with 33 additions and 1 deletion.
  1. +6 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +10 −0 src/index.js
  4. +16 −0 test.js
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

### v2.4.0
- Add support for descriptors [jamiter](https://github.com/jamiter) in [PR #99](https://github.com/apollographql/graphql-tag/pull/99)

### v2.3.0
- Add flow support [michalkvasnicak](https://github.com/michalkvasnicak) in [PR #98](https://github.com/apollographql/graphql-tag/pull/98)

### v2.2.2
- Make parsing line endings kind agnostic [vlasenko](https://github.com/vlasenko) in [PR #95](https://github.com/apollographql/graphql-tag/pull/95)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-tag",
"version": "2.2.2",
"version": "2.4.0",
"description": "A JavaScript template literal tag that parses GraphQL queries",
"main": "./lib/graphql-tag.umd.js",
"module": "./src/index.js",
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var parser = require('graphql/language/parser');
var buildASTSchema = require('graphql/utilities/buildASTSchema');

var parse = parser.parse;
var getDescription = buildASTSchema.getDescription;

// Strip insignificant whitespace
// Note that this could do a lot more, such as reorder fields etc.
@@ -83,6 +85,14 @@ function stripLoc(doc, removeLocAtThisLevel) {
});
}

if (!doc.description) {
var description = getDescription(doc);

if (description) {
doc.description = description;
}
}

if (docType !== '[object Object]') {
throw new Error('Unexpected input.');
}
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -433,5 +433,21 @@ const assert = require('chai').assert;
// `);
// });

describe('descriptors', function() {
it('adds comments as descriptors', function() {
const ast = gql`
# This is a type descriptor
type Foo {
# This is a field descriptor
bar: String
baz: Int
}
`;
assert.equal(ast.definitions[0].description, 'This is a type descriptor');
assert.equal(ast.definitions[0].fields[0].description, 'This is a field descriptor');
assert.equal(ast.definitions[0].fields[1].description, undefined);
})
})

});
});