Error: can't convert data to vector in simple index query

This may be a very simple problem, but this is my first time using GraphQL and FaunaDB. I’m trying to set up a simple database with links to sound files stored in an aws s3 bucket with some basic information stored along with them. I have an index all_stems that just points to the stems collection.

My schema:

type Stem {
    name: String!
    url: String!
    contributer: String
    description: String
    id: ID!
}

type Query {
    allStems: [Stem!]! @resolver (name: "get_all_stems")
}

type Mutation {
    addStem(
        name: String!
        url: String!
        contributer: String
        description: String
    ) : Stem @resolver (name: "add_stem")
}

and my two resolver functions are as follows

add_stem:

Query(
  Lambda(
    ["name", "url", "contributer", "description"],
    Create(Collection("stems"), {
      data: {
        name: Var("name"),
        url: Var("url"),
        description: Var("description"),
        contributer: Var("contributer"),
        id: NewId()
      }
    })
  )
)

get_all_stems:

Query(
  Lambda(
    "_",
    Map(Paginate(Match(Index("all_stems"))), Lambda("X", Get(Var("X"))))
  )
)

My addStem mutation works fine, but my problem is that when I try to run the allStems query in the GraphQL playground on the FaunaDB dashboard, like so:

query {
  allStems {
    name
  }
}

I get this error:

"Can't convert '{data: [{name: \"ambient1\"}, {name: \"crash\"}, {name: \"drum loop 1\"}]}' to Vector"

Being new to FaunaDB, I’m really not sure where I’ve gone wrong, as the information I need is present, but there seems to be some kind of type error.

Your query here is expecting you to return an array of documents from the Stem collection:

but you are returning an array of Stem documents that is wrapped in a Page due to your use of Paginate here:

Query(
  Lambda(
    "_",
    Map(Paginate(Match(Index("all_stems"))), Lambda("X", Get(Var("X"))))
  )
)

A Page is basically an object that has some before/after cursors, and a data property that holds the actual data. In this case data is your array of Stem documents that you actually want to return. So you can use a Select to pluck out that array and return it instead of returning the Page:


Query(
  Lambda(
    "_",
    Let({
        stemDocumentPage: Map(Paginate(Match(Index("all_stems"))), Lambda("X", Get(Var("X")))))
    },
        Select(['data'], Var('stemDocumentPage'))
    )
  )
)

You can also set the paginated argument to true which will alter the resulting schema to accept the page. That requires you to handle the pagination variables in your UDF, though, so it’s a bit more complicated.

@resolver docs hint about this.

UDF docs say more about making UDFs that return a page.

Here are some other notes.