Skip to content

Spec and implementation inconsistent about circular references in input types  #189

Closed
@kaqqao

Description

@kaqqao

The Type System spec, under Input objects, states (emphasis mine):

The Object type defined above is inappropriate for re-use here, because Objects can contain fields that express circular references or references to interfaces and unions, neither of which is appropriate for use as an input argument. For this reason, input objects have a separate type in the system.

The reference implementation indeed disallows interfaces and unions in inputs, implying the above sentence should be understood as a rule forbidding them and not just a recommendation against using them.
On the other hand, the implementation allows circular references in GraphQLInputObjectTypes.
E.g. the following is a legal declaration (ArticleInputType referring to ArticleInputType):

const ArticleInputType = new GraphQLInputObjectType({
  name: 'ArticleInput',
  fields: () => ({
    id:          { type: GraphQLInt },
    title:       { type: new GraphQLNonNull(GraphQLString) },
    body:        { type: GraphQLString },
    relatedArticles: { type: new GraphQLList(ArticleInputType) }
  })
});

This implies the sentence from the spec should be understood as a recommendation.

I suggest the wording in the corresponding spec section is changed to be consistent with the reference implementation or vice versa.
The current state leads to inconsistencies between the reference and other implementations, depending on their interpretation of the spec.

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