Get schema for a collection using GraphQL API

How can we return the schema for a specific collection, “Customers” for example?

Thank you.

@georgep Everything in Fauna is document which can be retrieved using its ref.

Example to list all Collections.

Paginate(Collections())

{
  data: [
    Collection("posts"),
    Collection("testevents"),
    Collection("TestEvents")
  ]
}

Example to Get details about a Collection.

Get(Collection("posts"))

{
  ref: Collection("posts"),
  ts: 1605135452590000,
  history_days: 30,
  name: "posts"
}

Thanks Jay,

I’m a little confused. I tried this:

Get(Collection(“Customers”))

{
ref: Collection(“Customers”),
ts: 1605135452590000,
history_days: 30,
name: “Customers”
}

and this was the response:

Get(Collection(“Customers”))

{
ref: Collection(“Customers”),
ts: 1605135452590000,
history_days: 30,
name: “Customers”
}

Error: Unexpected token ‘:’

I’m wanting to see a schema something like:

type Customer {
id: ID!
co_Id: String
name: String!
altBusinessNames: String
street: String
city: String
state: String!
…ect.

@georgep Fauna Collection is not tied to a strict Schema. For example, one document can have 10 fields and other can have 15. If all the Documents in a Collection have same fields then you can use Documents() Index +Get() to get one document and then use the fields.

From the GraphQL tab in the dashboard, I uploaded a schema document for the database. Doesn’t that definition live somewhere?

It resides in the Collection definition under data. Here is an example from one my Collection created using GraphQL.

Get(Collection("Order"))

{
  ref: Collection("Order"),
  ts: 1600954977098000,
  history_days: 30,
  name: "Order",
  data: {
    gql: {
      ts: Time("2020-09-24T13:42:56.908842Z"),
      meta: {
        name: "Order",
        fields: [
          {
            name: "orderid",
            type: {
              NotNull: {
                Named: "Int"
              }
            }
          },
          {
            name: "orderdate",
            type: {
              NotNull: {
                Named: "Date"
              }
            }
          },
          {
            name: "orderTime",
            type: {
              NotNull: {
                Named: "Time"
              }
            }
          }
        ],
        directives: [
          {
            name: "collection",
            args: {
              name: "Order"
            }
          }
        ]
      }
    }
  }
}

I’m assuming that entire block of text was the input. If so, then you need to know the schema to input the query. Is there a way to say “show be the schema for collection X”?

The command is Get(Collection("Order")), rest is the output and as you can see data section tells what the GraphQL schema looks like.

Right, but this post is a question on:

How to return a schema for a collection.

I uploaded a schema via GraphQL and now I want to write a query that show the the schema for “Customers”.

I think you said that FQL cannot show the schema, but can I do this via GraphQL?

You can see the Schema in SCHEMA tab on Playground or you can run the Introspection queries to get the schema.

Something like this for my Order collection.

Thank you that’s what I’m looking for:

{
__type(name: “Customer”) {
name
fields {
name
type {
name
}
}
}
}

Worked perfect!