Graphql-js: Cyclical Types?

Created on 9 Oct 2015  路  2Comments  路  Source: graphql/graphql-js

We've all seen 'em. Are they doable? Doing it with Babel gives you a "temporal dead zone" & the type is undefined.

const PersonType = new GraphQLObjectType({
  name: "Person",
  friends: {
    type: new GraphQLList(PersonType),
    resolve: () { ... },
  }
});

Most helpful comment

You can wrap the fields in a function, which should help:

const PersonType = new GraphQLObjectType({
  name: "Person",
  fields: () => ({
    friends: {
      type: new GraphQLList(PersonType),
      resolve() { ... },
    },
  }),
});

All 2 comments

You can wrap the fields in a function, which should help:

const PersonType = new GraphQLObjectType({
  name: "Person",
  fields: () => ({
    friends: {
      type: new GraphQLList(PersonType),
      resolve() { ... },
    },
  }),
});

Whoa, say WHAT!? That's useful!

I'll re-open if that doesn't work.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings