content-model-graph icon indicating copy to clipboard operation
content-model-graph copied to clipboard

Incorrect model when using references as types

Open fvieira opened this issue 5 years ago • 1 comments

Due to GraphQL restrictions, references cannot be inline in arrays and have to be extracted and referenced as types. The issue is that this library faild to build the correct model when the references are not inline.

This is the code for inline references and the model built (correct):

{
  name: 'myObject',
  type: 'object',
  fields: [
    {
      name: 'myArrayOfReferences',
      type: 'array',
      of: [
        {
          name: 'myReferencedTypeReference',
          type: 'reference',
          to: {
            type: 'myReferencedType',
          },
        },
      ],
    },
  ],
}

correct

And this is the code with the reference as an external type (which is equivalent to the previous code) and the model built (incorrect):

{
  name: 'myReferencedTypeReference',
  type: 'reference',
  to: {
    type: 'myReferencedType',
  },
},
{
  name: 'myObject',
  type: 'object',
  fields: [
    {
      name: 'myArrayOfReferences',
      type: 'array',
      of: [
        {
          type: 'myReferencedTypeReference',
        },
      ],
    },
  ],
}

incorrect

fvieira avatar Mar 25 '20 16:03 fvieira

I've at least got some tests running against this repo now, so we can now modify the get nodes function and the fixtures to solve your test case.

camjc avatar Apr 03 '20 07:04 camjc