Skip to content

Commit 32487a0

Browse files
committed
Merge branch 'beta' of https://github.com/herbsjs/herbs2gql into beta
2 parents 2c3c451 + 3c5ff0f commit 32487a0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/herbarium2gql.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const defaultResolver = require('./defaultResolver')
22
const entity2type = require('./entity2type')
3+
const entity2input = require('./entity2input')
34
const usecase2mutation = require('./usecase2mutation')
45
const usecase2query = require('./usecase2query')
6+
const { entity, field } = require('@herbsjs/herbs')
7+
58

69
function herbs2gql({herbarium, resolver = defaultResolver}) {
710
const { usecases, entities, crud } = herbarium
@@ -33,6 +36,15 @@ function herbs2gql({herbarium, resolver = defaultResolver}) {
3336
const types = [
3437
defaultSchema,
3538
...entitiesName.map((entity) => [entity2type(entity)]),
39+
...entitiesName.map((entity) => [entity2input(entity)]),
40+
...Array.from(usecases.all).map(([_, { id, usecase }]) => {
41+
const schema = usecase().requestSchema
42+
// convert each schema's key into a Field object
43+
Object.keys(schema).forEach((key) => {
44+
schema[key] = field(schema[key])
45+
})
46+
return [entity2input(entity(id, schema))]
47+
})
3648
]
3749

3850
return { types, queries, mutations }

test/herbarium2gql.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ describe('Hebarium to GQL', () => {
1515
[
1616
"type CoolEntity {\nid: Float\nstringField: String!\nboolField: Boolean\ndateField: Date\nnumberField: Float\n}",
1717
],
18+
[
19+
"input CoolEntityInput {\nid: Float\nstringField: String!\nboolField: Boolean\ndateField: Date\nnumberField: Float\n}"
20+
],
21+
[
22+
"input CreateSomethingCoolInput {\ncoolEntity: [CoolEntityInput]\n}"
23+
],
24+
[
25+
"input GetSomethingCoolInput {\nid: Float\n}"
26+
],
27+
[
28+
"input GivenAnUseCaseThatResturnsDateInput {\nid: Float\ndate: Date\n}"
29+
]
1830
])
1931
assert.deepStrictEqual(
2032
queries[0][0],

0 commit comments

Comments
 (0)