seemcat
seemcat

Reputation: 644

What does "graphql.NewList(type)" do?

As it turns out, graphql-go's help doc is not beginner friendly. I'm simply wondering what .NewList() does in, say, the following code: Type: graphql.NewList(types.Workouts)

Upvotes: 0

Views: 223

Answers (1)

Yegor
Yegor

Reputation: 3950

It means array type

Lists work in a similar way: We can use a type modifier to mark a type as a List, which indicates that this field will return an array of that type. In the schema language, this is denoted by wrapping the type in square brackets, [ and ].

// js
languages: {
    type: new GraphQLNonNull(new GraphQLList(GraphQLString))
}

// schema language
languages: [String]! // returns empty array or array of strings

docs

Upvotes: 1

Related Questions