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

schema cannot parse complex objects? #243

Open
shaunc opened this issue Jan 6, 2017 · 1 comment
Open

schema cannot parse complex objects? #243

shaunc opened this issue Jan 6, 2017 · 1 comment

Comments

@shaunc
Copy link

shaunc commented Jan 6, 2017

When I modify example/resources/tuples.js to contain an array of objects, I get an error. I checked that it works with generic "Joi" though, and according to json-api spec: "Complex data structures involving JSON objects and arrays are allowed as attribute values.".

It seems like a bug... but perhaps there is a reason for it? Why not use Joi directly (which seems to be extensible for relationship types)?

--- a/example/resources/tuples.js
+++ b/example/resources/tuples.js
@@ -9,7 +9,8 @@ jsonApi.define({
   searchParams: { },
   attributes: {
     media: jsonApi.Joi.many('articles', 'photos'),
-    preferred: jsonApi.Joi.one('articles', 'photos')
+    preferred: jsonApi.Joi.one('articles', 'photos'),
+    foo: jsonApi.Joi.array().items(jsonApi.Joi.object())
   },
   examples: [

I get the following error:

  1) Testing jsonapi-server "before all" hook:
     Error: Unable to parse Joi type, got {"isJoi":true,"_type":"object","_settings":null,"_valids":{"_set":[]},"_invalids":{"_set":[]},"_tests":[],"_refs":[],"_flags":{},"_description":null,"_unit":null,"_notes":[],"_tags":[],"_examples":[],"_meta":[],"_inner":{"children":null,"renames":[],"dependencies":[],"patterns":[]}}
      at Object.joiConverter.simpleAttribute.joiScheme [as simpleAttribute] (lib/graphQl/joiConverter.js:38:11)
      at Object.joiConverter.simpleAttribute.joiScheme [as simpleAttribute] (lib/graphQl/joiConverter.js:22:38)
      at Object.joiConverter.swap (lib/graphQl/joiConverter.js:46:25)
      at Object.keys.forEach.attribute (lib/graphQl/readTypes.js:41:30)
      at Array.forEach (native)
      at fields (lib/graphQl/readTypes.js:36:46)
      at resolveThunk (node_modules/graphql/type/definition.js:115:40)
      at defineFieldMap (node_modules/graphql/type/definition.js:265:18)
      at GraphQLObjectType.getFields (node_modules/graphql/type/definition.js:235:44)
      at node_modules/graphql/type/schema.js:207:27
      at typeMapReducer (node_modules/graphql/type/schema.js:219:7)
      at typeMapReducer (node_modules/graphql/type/schema.js:187:12)
      at node_modules/graphql/type/schema.js:217:22
      at Array.forEach (native)
      at node_modules/graphql/type/schema.js:208:29
      at typeMapReducer (node_modules/graphql/type/schema.js:219:7)
      at Array.reduce (native)
      at new GraphQLSchema (node_modules/graphql/type/schema.js:95:34)
      at Object.jsonApiGraphQL.generate.allResourceConfig [as generate] (lib/graphQl/index.js:29:10)
      at Object.jsonApiGraphQL.with.app [as with] (lib/graphQl/index.js:17:28)
      at Object.router.applyMiddleware (lib/router.js:76:15)
      at Object.jsonApi.start (lib/jsonApi.js:116:10)
      at Context.before (test/404.js:38:23)
@theninj4
Copy link
Contributor

theninj4 commented Jan 6, 2017

A member of the community kindly implemented array support (we don't have object support in master yet). They added in some build-time throwing of Errors to make the lack of support for objects more obvious (the GraphQl errors are a bit... mind boggling). The errors you're seeing is that validation kicking in.

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

Successfully merging a pull request may close this issue.

2 participants