Skip to content

Joi Objects as resource attributes cause GraphQL to fail #101

@jplabadie

Description

@jplabadie

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions