graphqlfaunadb

How can I create a query on the FaunaDb cli?


I am trying to create a query on the Fauna DB command line interface.

I have a collection and if I run

Map(Paginate(Documents(Collection('users'))), Lambda(x => Get(x)))

I get

data: [
    {
        ref: Ref(Collection("users"), "350926483869401600"),
        ts: 1670928424920000,
        data: {
            username: 'jeff',
            login_id: '123621b8-d6fc-465e-90ae-dca8d83e3321'
        }
    }
]

This page suggests that I can write a query thus

{users{username}}

But when I attempt it the cli hangs on the ... prompt

If I try

{
    users
    {
        username
    }
}

it returns

Uncaught ReferenceError: users is not defined

What am I doing wrong?


Solution

  • The page you link to is the general documentation for GraphQL, which is independent of Fauna.

    The Fauna CLI is not a GraphQL client. The shell command lets you query your databases with FQL. The online shell in the customer Dashboard is the same. Both the CLI shell and online shell use the Javascript FQL drivers, so the shell is treating your input like javascript and throwing an error because there is no users variable.

    To use GraphQL with Fauna, you must first upload a GraphQL schema through the Dashboard (Check out our GraphQL quick-start tutorial), or using the CLI upload-graphql-schema command, or even directly with an HTTP request.

    Once you have uploaded a GraphQL schema, Fauna will host a GraphQL API that you can query through the playground in the Dashboard, or use your preferred GraphQL client.