How to use the GraphQLList function from graphql

Find comprehensive JavaScript graphql.GraphQLList code examples handpicked from public code repositorys.

GraphQLList is a type constructor for creating a list type in a GraphQL schema.

110
111
112
113
114
115
116
117
118
119
      gt: { type: fields[field].type },
      gte: { type: fields[field].type },
      lt: { type: fields[field].type },
      lte: { type: fields[field].type },
      like: { type: fields[field].type },
      in: { type: new graphql.GraphQLList(fields[field].type) },
      nin: { type: new graphql.GraphQLList(fields[field].type) }
    }
  })
}
fork icon85
star icon888
watch icon16

+ 197 other calls in file

15
16
17
18
19
20
21
22
23
24
},
selectAll: {
  args: element.args,
  description: 'Grab all child elements of a tag',
  resolve: element.resolve,
  type: new graphql.GraphQLList(element.type),
},
count: {
  args: element.args,
  description: 'Get a count of provided elements',
fork icon48
star icon635
watch icon13

How does graphql.GraphQLList work?

GraphQLList is a type constructor in the GraphQL.js library that is used to represent a list of another type in a GraphQL schema. It accepts a type as an argument and returns a new list type that represents a list of values of that type. When a field in a GraphQL query returns a list, it is represented as an instance of GraphQLList.

158
159
160
161
162
163
164
165
166
167
name: 'Query',
description: 'Root query object',
fields: () => {
  return {
    user: {
      type: new GraphQLList(userType),
      args: {
        uid: {
          type: GraphQLInt
        },
fork icon54
star icon304
watch icon13

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
const ScalarType = graphql.GraphQLScalarType;
const ObjectType = graphql.GraphQLObjectType;
const UnionType = graphql.GraphQLUnionType;
const NonNullType = graphql.GraphQLNonNull;
const EnumType = graphql.GraphQLEnumType;
const ListType = graphql.GraphQLList;

const builtInScalars = {
  'String': graphql.GraphQLString,
  'Int': graphql.GraphQLInt,
fork icon13
star icon203
watch icon10

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const {
  GraphQLSchema,
  GraphQLObjectType,
  GraphQLString,
  GraphQLList,
} = require("graphql");

const authorType = new GraphQLObjectType({
  name: "Author",
  fields: () => ({
    id: { type: GraphQLString },
    name: { type: GraphQLString },
    books: {
      type: GraphQLList(bookType),
      resolve: (author) => getBooksByAuthorId(author.id),
    },
  }),
});

const bookType = new GraphQLObjectType({
  name: "Book",
  fields: () => ({
    id: { type: GraphQLString },
    title: { type: GraphQLString },
  }),
});

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: "Query",
    fields: {
      authors: {
        type: GraphQLList(authorType),
        resolve: () => getAuthors(),
      },
    },
  }),
});

In this example, GraphQLList is used to define a list of books that an author has written. The books field of the authorType is defined as a list of bookType, and the resolve function returns a list of books written by the author with the given ID. Additionally, GraphQLList is used to define a list of authors in the authors field of the root Query type.

27
28
29
30
31
32
33
34
35
36
        },
        description: {
            type: graphql.GraphQLString
        },
        users: {
            type: new graphql.GraphQLList(usersType),
            resolve: group => groupsDomain.getUsers(group)
        }
    })
});
fork icon43
star icon139
watch icon16

131
132
133
134
135
136
137
138
139
140
test("returns markdown link surrounded by [] for GraphQL list/array", () => {
  expect.hasAssertions();

  const entityName = "TestObjectList";
  const slug = "test-object-list";
  const type = new GraphQLList(
    new GraphQLObjectType({
      name: entityName,
    }),
  );
fork icon25
star icon107
watch icon0

95
96
97
98
99
100
101
102
103
104

const RootQuery = new GraphQLObjectType({
  name: 'RootQueryType',
  fields: {
    launches: {
      type: new GraphQLList(LaunchType),
      resolve(parent, args) {
        return axios.get('https://api.spacexdata.com/v3/launches').then(res => res.data);
      }
    }
fork icon9
star icon18
watch icon2

44
45
46
47
48
49
50
51
52
53
    }
},

// rockets
rockets: {
    type: new GraphQLList(RocketType),
    resolve() {
        return axios.get('https://api.spacexdata.com/v3/rockets').then(res => res.data);
    }
},
fork icon23
star icon16
watch icon5

+ 3 other calls in file

135
136
137
138
139
140
141
142
143

switch (valueType.toLowerCase()) {
        case 'array':
                var itemsSchema = (0, _lodash.get)(schema, 'items');

                return new _graphql.GraphQLList(computeType(Object.assign({}, itemsSchema, isInput ? { 'x-isInput': true } : {}), operationsDescriptions, swagger, idFormats, typesBag, parentTypePath));
                break;
        case 'object':
                checkObjectSchemaForUnsupportedFeatures(schema);
fork icon5
star icon7
watch icon3

62
63
64
65
66
67
68
69
70
71
  if (!createInputObjectType) return

  const args = {
    [ARGS.input]: { type: new GraphQLNonNull(new GraphQLList(createInputObjectType)) }
  }
  return { type: new GraphQLList(entityObjectType), args }
}

const _update = entity => {
  const entityObjectType = objectGenerator(cache).entityToObjectType(entity)
fork icon3
star icon23
watch icon8

+ 5 other calls in file

38
39
40
41
42
43
44
45
46
47
const ChuckNorrisQueryType = new GraphQLObjectType({
  name: 'ChuckNorrisQuerytype',
  description: 'Chuck Norris Query Schema',
  fields: {
    quotes: {
      type: new GraphQLList(QuoteType),
      resolve: () => Quotes 
    }
  }
});
fork icon1
star icon5
watch icon2

17
18
19
20
21
22
23
24
25
26
    resolve(parent, args){
        return Quiz.find( { userId: parent.id })
    }
},
submissions: {
    type: new GraphQLList(SubmissionType),
    resolve(parent, args){
        return Submission.find({ userId: parent.id })
    }
}
fork icon5
star icon0
watch icon0

+ 7 other calls in file

77
78
79
80
81
82
83
84
85
86
    }

},

getAllArticles: {
    type: new GraphQLList(ArticleType),
    resolve()
    {
        const result = query`
          FOR article IN Articles
fork icon2
star icon26
watch icon0

900
901
902
903
904
905
906
907
908
909
910
911
    fields: () => {
        let f = getItemFields(true, true);


        f.getMob = { type: mobSchema.types.mobType },
        f.getQuest = { type: questSchema.types.questType },
        f.getHistories = { type: new graphql.GraphQLList(itemHistoryType) }


        return f;
    }
});
fork icon3
star icon6
watch icon0

+ 7 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const { CategoryType } = require("../typeDefs/category.type");
const { CategoryModel } = require("../../models/categories");
const { GraphQLList, GraphQLString } = require("graphql");


const CategoriesResolver = {
    type: new GraphQLList(CategoryType),
    resolve : async () => {
        const categories = await CategoryModel.find({parent : undefined});
        return categories
    }
fork icon0
star icon2
watch icon2

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14
15






const users = {
  name: "Get users and all info",
  type: new GraphQLList(UserType),
  description: "Returns a list of users and all info",
  async resolve() {
    const users = await User.find();

fork icon0
star icon1
watch icon0

+ 2 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const { GraphQLList, GraphQLString } = require("graphql")
const { CategoryModel } = require("../../models/categories")
const { CategoryType } = require("../typeDefs/category.type")


const CategoryResolver = {
    type : new GraphQLList(CategoryType),
    resolve : async () => {
        const categories =await CategoryModel.find({parent : undefined})
        return categories
    }
fork icon0
star icon0
watch icon1

+ 35 other calls in file

440
441
442
443
444
445
446
447
448
449
},
_nends_with: {
    type: graphql_1.GraphQLString,
},
_in: {
    type: new graphql_1.GraphQLList(graphql_1.GraphQLString),
},
_nin: {
    type: new graphql_1.GraphQLList(graphql_1.GraphQLString),
},
fork icon0
star icon0
watch icon1

+ 816 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const { GraphQLList, GraphQLString } = require("graphql");
const { CategoryMoldle } = require("../../models/categories");
const { categoryTypes } = require("../typeDefs/category.types");


const categoryResolver = {
    type:new GraphQLList(categoryTypes),
    resolve: async()=>{
        const category = await CategoryMoldle.find({parent: undefined});
        return category
    }
fork icon0
star icon0
watch icon2

9
10
11
12
13
14
15
16
17
18
args: {
    eventDate: { type: GraphQLString },
    eventTrip: { type: GraphQLString },
    eventType: { type: GraphQLString },
    eventStatus: { type: GraphQLBoolean },
    users: { type: GraphQLList(InputEventUserType) }
},
async resolve(_, { eventDate, eventTrip, eventType, eventStatus, users }, { verifiedUser }) {
    if (!verifiedUser) throw new Error("Debes iniciar sesion para realizar esta accion");
    if (verifiedUser.userType !== "admin") throw new Error("Solo un administrador puede eliminar eventos");
fork icon0
star icon0
watch icon0

+ 11 other calls in file