Skip to content

Commit

Permalink
Merge branch 'master' of github.com:alphasights/ember-graphql-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rabie committed Feb 2, 2018
2 parents da6ee6c + 983abec commit 15f293a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions addon/generator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { typeOf } from '@ember/utils';
import ArgumentSet from 'ember-graphql-adapter/types/argument-set';
import SelectionSet from 'ember-graphql-adapter/types/selection-set';

export default {
openingToken: ' {',
Expand Down Expand Up @@ -54,7 +56,11 @@ export default {
value = this.wrapInStringTokens(value);
} else if (typeOf(value) === 'array') {
value = this.argumentArrayOpeningToken + this.wrapArrayInStringTokens(value) + this.argumentArrayClosingToken;
} else if (value instanceof SelectionSet || value instanceof ArgumentSet) {
value = this.argumentObjectOpeningToken + this.generateArgumentSet(value) + this.argumentObjectClosingToken;
} else if (typeOf(value) === 'object') {
value = ArgumentSet.fromQuery(value);

value = this.argumentObjectOpeningToken + this.generateArgumentSet(value) + this.argumentObjectClosingToken;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/unit/generator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as Type from 'ember-graphql-adapter/types';
module('unit:ember-graphql-adapter/generator');

test('all the things', function(assert) {
assert.expect(1)

let fieldId = new Type.Field('id');
let fieldStatus = new Type.Field('status');

Expand All @@ -20,7 +22,8 @@ test('all the things', function(assert) {
new Type.Argument('embedded', new Type.ArgumentSet(new Type.Argument('id', 1))),
new Type.Argument('limit', 10),
new Type.Argument('offset', 0),
new Type.Argument('objectArray', [{ foo: 'bar', bar: 'foo' }])
new Type.Argument('objectArray', [{ foo: 'bar', bar: 'foo' }]),
new Type.Argument('object', { id: 'hi' })
);
let post = new Type.Field('post', 'postAlias', postArgumentSet, postSelectionSet);

Expand All @@ -30,6 +33,6 @@ test('all the things', function(assert) {

assert.equal(
Generator.generate(operation),
`query postsQuery { postAlias: post(ids: ["1","2","3"], status: "active", embedded: { id: 1 }, limit: 10, offset: 0, objectArray: [{ foo: "bar", bar: "foo" }]) { id status author { id username } } }`
`query postsQuery { postAlias: post(ids: ["1","2","3"], status: "active", embedded: { id: 1 }, limit: 10, offset: 0, objectArray: [{ foo: "bar", bar: "foo" }], object: { id: "hi" }) { id status author { id username } } }`
);
});

0 comments on commit 15f293a

Please sign in to comment.