Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joi Objects as resource attributes cause GraphQL to fail #101

Open
jplabadie opened this issue Aug 8, 2019 · 0 comments
Open

Joi Objects as resource attributes cause GraphQL to fail #101

jplabadie opened this issue Aug 8, 2019 · 0 comments

Comments

@jplabadie
Copy link

jplabadie commented Aug 8, 2019

var schema = jsonApi.Joi.object().keys({
names: jsonApi.Joi.string()
.description('A combination of name elements as the field describes.')
.example('John Smith, etc.'),
});

jsonApi.define({
namespace: 'json:api',
resource: 'names',
description: 'a collection of names',
handlers: namesHandler,
primaryKey: 'uuid',
searchParams: { query: jsonApi.Joi.string()},
attributes: {
prefix: jsonApi.Joi.string()
.optional()
.description('The persons prefix')
.example('Dr'),
firstname: jsonApi.Joi.string()
.description('The persons first name')
.example('John'),
middlename: jsonApi.Joi.string()
.optional()
.description('The persons middle name')
.example('Perry'),
lastname: jsonApi.Joi.string()
.description('The persons last name')
.example('Smith'),
suffix: jsonApi.Joi.string()
.optional()
.description('The persons suffix')
.example('Ph.D'),
formats: schema
.description('The formatted name.')
},
examples: [
{
id: 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116',
type: 'names',
prefix: 'Dr.',
firstname: 'Oli',
lastname: 'Rumbelow',
suffix: 'M.D.',
formats: {
name: "LEVENTE WIKSTRÖM",
}
},
{
id: '32fb0105-acaa-4adb-9ec4-8b49633695e1',
type: 'names',
firstname: 'Pedro',
lastname: 'Romano',
},
]
})

Defining a resource as demonstrated above creates a valid, functioning json-api REST endpoint that works as expected. Producing :
{..."data":[{"type":"names","id":"cc5cca2e-0dd8-4b95-8cfc-a11230e73116",
"attributes":{"prefix":"Dr.","firstname":"Oli","lastname":"Rumbelow","suffix":"M.D.",
"formats":{"name":"LEVENTE WIKSTRÖM",}},
"links":{
"self":"http://localhost:16006/v1/names/cc5cca2e-0dd8-4b95-8cfc-a11230e73116"}
}

However, the graphIQL endpoint stops working correctly and reports:
{
"errors": [
{
"message": "The type of names.formats must be Output Type but got: [function GraphQLObjectType]."
},
{
"message": "Expected GraphQL named type but got: [function GraphQLObjectType]."
},
{
"message": "The type of namesWrite.formats must be Input Type but got: [function GraphQLObjectType]."
}
]
}

Is there a workaround for this so that nested objects can be used for both standard jsonapi rest and graphql? Does the framework support object nesting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant