graphql-compose-json
Advanced tools
Comparing version
@@ -208,2 +208,62 @@ "use strict"; | ||
}); | ||
it('check array of swallow objects', async () => { | ||
const restApiResponse = { | ||
name: 'Luke Skywalker', | ||
limbs: [{ | ||
kind: 'arm', | ||
position: 'left', | ||
length: 76 | ||
}, { | ||
kind: 'arm', | ||
position: 'left', | ||
length: 76 | ||
}, { | ||
kind: 'leg', | ||
position: 'left', | ||
length: 81 | ||
}, { | ||
kind: 'leg', | ||
position: 'right', | ||
length: 82 | ||
}] | ||
}; | ||
const PersonTC = (0, _index.composeWithJson)('PersonCustom', restApiResponse); | ||
const schema1 = new GraphQLSchema({ | ||
query: new GraphQLObjectType({ | ||
name: 'Query', | ||
fields: { | ||
person: { | ||
type: PersonTC.getType(), | ||
resolve: () => { | ||
return restApiResponse; | ||
} | ||
} | ||
} | ||
}) | ||
}); | ||
const res = await _graphqlCompose.graphql.graphql(schema1, `{ | ||
person { | ||
name | ||
limbs { | ||
length | ||
} | ||
} | ||
}`); | ||
expect(res).toEqual({ | ||
data: { | ||
person: { | ||
name: 'Luke Skywalker', | ||
limbs: [{ | ||
length: 76 | ||
}, { | ||
length: 76 | ||
}, { | ||
length: 81 | ||
}, { | ||
length: 82 | ||
}] | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
@@ -39,2 +39,17 @@ "use strict"; | ||
}); | ||
it('of object', () => { | ||
const spy = jest.spyOn(_ObjectParser.default, 'createTC'); | ||
const valueAsArrayOfObjects = [{ | ||
a: 123 | ||
}, { | ||
a: 456 | ||
}]; | ||
_ObjectParser.default.getFieldConfig(valueAsArrayOfObjects, { | ||
typeName: 'ParentTypeName', | ||
fieldName: 'subDocument' | ||
}); | ||
expect(spy).toHaveBeenCalledWith('ParentTypeName_SubDocument', valueAsArrayOfObjects[0]); | ||
}); | ||
it('of any', () => { | ||
@@ -41,0 +56,0 @@ expect(_ObjectParser.default.getFieldConfig([null])).toEqual(['JSON']); |
@@ -40,3 +40,7 @@ "use strict"; | ||
if (Array.isArray(val)) return ['JSON']; | ||
return [this.getFieldConfig(val)]; | ||
const args = opts && opts.typeName && opts.fieldName ? { | ||
typeName: opts.typeName, | ||
fieldName: opts.fieldName | ||
} : {}; | ||
return [this.getFieldConfig(val, args)]; | ||
} | ||
@@ -43,0 +47,0 @@ |
{ | ||
"name": "graphql-compose-json", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "This is a plugin for `graphql-compose`, which generates GraphQLTypes from any JSON.", | ||
@@ -40,2 +40,3 @@ "files": [ | ||
"babel-jest": "^24.8.0", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.16.0", | ||
@@ -68,3 +69,3 @@ "eslint-config-airbnb-base": "^13.1.0", | ||
"flow": "./node_modules/.bin/flow", | ||
"test": "npm run coverage && npm run lint && npm run flow", | ||
"test": "cross-env NODE_ENV=test npm run coverage && npm run lint && npm run flow", | ||
"semantic-release": "semantic-release", | ||
@@ -71,0 +72,0 @@ "fixture-demo": "./node_modules/.bin/babel-node ./src/__fixtures__/app.js" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
49643
9.28%1129
15.79%28
3.7%