I have the following graphQL Schema. I want to query the Decor type by multiple reference ID’s. I have an array of Decor documents in a string and I want to query all the Decor types in one query.
type Catalog {
decor: Boolean
clothing: Boolean
supplies: Boolean
furniture: Boolean
owner: User
}
type Decor {
description: String
pieces: Int
purchaser: String
alterations: Boolean
cost: Int
purchaseDate: Date
category: String
image: String
itemNum: Int
owner: User!
visible: Boolean
}
type DecorSheet {
sheetName: String
refIdArray: String
owner: User!
}
type User {
email: String! @unique
catalog: Catalog
decor: [Decor!] @relation
decorSheet: [DecorSheet!] @relation
}
So if I have the following graphQL query, is there a way to pass multiple id’s to it and get all the matching. Do I need to structure my schema differently?
@anders You cannot do this with the default findDecorByID. However, you can write a query with the @resolver directive, which accepts a list of refs. You can use Map[list of refs] in the corresponding UDF, Paginate, Lambda, Get to get the data. I hope this helps.
@Jay-Fauna
How would one write this query would it be something like this, I know the @resolver part will create a blank udf for me to modify, but what to put in this query so I can pass a list of ref’s I am not sure.
type Query{
AllDecorByID:[ID] @resolver (name: "grabAll")
}
In any case, have you tried to use just the variable by itself? Jay left in a couple of typos for you to work out – really make sure you know what you’re doin’
// ...
data: Map(
Var("get_multiple_decors"), // <= note wrapped in `Var` function
Lambda("x", Get(Ref(Collection("User"), Var("x"))))
)
// ...
GraphQL API expects an Array of Users getMulitpleUsers(UserId: [ID!]): [User!] @resolver(name: "get_multiple_users")
so, you have to make sure UDF returns the Array of Users.