Skip to content

Commit

Permalink
Add getDescription.js
Browse files Browse the repository at this point in the history
  • Loading branch information
migueloller committed Jan 31, 2017
1 parent f898798 commit 30c4948
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/build/__tests__/getDescription-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* @flow */

import { parse } from 'graphql/language';
import getDescription from '../getDescription';

describe('getDescription()', () => {
const generateNode = description => parse(`
# ${description === undefined ? '' : description}
type Type {
int: Int
}
`).definitions[0];

test('gets description', () => {
const description = 'A description.';
expect(getDescription(generateNode(description))).toBe(description);
});

test('returns undefined if there\'s no description', () => {
expect(getDescription(generateNode())).toBeUndefined();
});

test('return undefined if there\'s an empty description', () => {
expect(getDescription(generateNode(' '))).toBeUndefined();
});
});
6 changes: 6 additions & 0 deletions src/build/getDescription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @flow */

import type { Location } from 'graphql/language';
import { getDescription } from 'graphql/utilities/buildASTSchema';

export default (node: { loc?: Location }) => getDescription(node) || undefined;

0 comments on commit 30c4948

Please sign in to comment.