GraphQLでNonNullなList

  1. フィールド自身がNonNull
  2. 要素がNonNull
  3. その両方

があって

let QueryType = new GraphQLObjectType({
  name: 'Query',
  fields: {
    list1: {
      type: new GraphQLNonNull(new GraphQLList(GraphQLString)),
      resolve: () => arr1,
    },
    list2: {
      type: new GraphQLList(new GraphQLNonNull(GraphQLString)),
      resolve: () => arr2,
    },
    list3: {
      type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))),
      resolve: () => arr3,
    },
  },
});

GraphQLの型で表現するとこうなる。

type Query {
  list1: [String]!
  list2: [String!]
  list3: [String!]!
}

違いはこんな感じ

  • list1
    • null : NG
    • ['foo', null] : OK
    • [] : OK
  • list2
    • null : OK
    • ['foo', null] : NG
    • [] : OK
  • list3
    • null : NG
    • ['foo', null] : NG
    • [] : OK