Using Time data type in graphql field

I want to have a time stamp in one of my structs. But since there is no built-in Time data type in graphql, should I use ToString and store the time stamp as a string? Or will fauna do the “stringify” call implicitly when returning?

Date : A date value. The GraphQL API communicates and renders these as strings in the format yyyy-MM-dd , but they are stored as FQL dates.

Time : A timestamp value. The GraphQL API communicates and renders these as strings in the format yyyy-MM-ddTHH:mm:ss.SSSZ , but they are stored as FQL timestamps.

More info here

Thanks! I am getting an error though in the response of the mutation call:

"Can't convert '\"2020-09-23T18:35:21.154355Z\"' to Instant"

Time format shoud be in yyyy-MM-ddTHH:mm:ss.SSSZ

Here is a small example

Schema

type Order {
    orderid: Int!
    orderdate: Date!
    orderTime: Time!
}

type Query {
    allOrders: [Order!]
    findOrdersByDate(date: Date!):[Order!] @resolver(name:"findOrdersByDate")
}

UDF findOrdersByDate (internally uses Index orders_by_orderdate

Update(
  Function("findOrdersByDate"),
  {
    body: Query(Lambda(["orderdate"],
       Select(["data"],Map(Paginate(Match(Index("orders_by_orderdate"),Var("orderdate"))),Lambda("x", Get(Var("x")))))
      )
    )
  }
)

Index orders_by_orderdate

CreateIndex(
{
name: "orders_by_orderdate",
source: Collection("Order"),
terms: [{ "field": ["data", "orderdate"]}]
});

Mutation createOrder


Query allOrders

Query findOrdersByDate

On FQL side, this is how function is called

Call(Function("findOrdersByDate"), [Date("2020-09-23")])

[
  {
    ref: Ref(Collection("Order"), "277491149556417042"),
    ts: 1600895032395000,
    data: {
      orderid: 1,
      orderdate: Date("2020-09-23"),
      orderTime: Time("2020-09-23T17:01:00Z")
    }
  },
  {
    ref: Ref(Collection("Order"), "277494987968479763"),
    ts: 1600898692960000,
    data: {
      orderid: 2,
      orderdate: Date("2020-09-23"),
      orderTime: Time("2020-09-23T19:01:00Z")
    }
  }
]

Hope this helps.

Thanks for all the examples. Here is my code that is giving me the error:

Schema:

type Session {
  session_id: ID
  start_ts: Time
  end_ts: Time
}

type Mutation {
  startSession(id: ID): Session! @resolver(name: "startSession")
}

UDF

Query(
  Lambda(
    "_",
    Create(Collection("Session"), {
      data: { session_id: NewId(), start_ts: Now() }
    })
  )
)

Calling from the GraphQL playground:

It works fine for me and I have no explanation on why it does not for you. Can you try once in a new database ?

type Order {
    orderid: Int!
    orderdate: Date!
    orderTime: Time!
}

type Session {
  session_id: ID
  start_ts: Time
  end_ts: Time
}

type Query {
    allOrders: [Order!]
    findOrdersByDate(date: Date!):[Order!] @resolver(name:"findOrdersByDate")
}

type Mutation {
  startSession(id: ID): Session! @resolver(name: "startSession")
}
Update(Function("startSession"), {
  body: Query(
    Lambda(
      "_",
      Create(Collection("Session"), {
        data: { session_id: NewId(), start_ts: Now() }
      })
    )
  )
}

Oh, that’s interesting. I’ve also noticed that schema updates aren’t applied on that DB either. Could be the same root cause.

OK this works as expected! Curious why this ended up in this state. Thanks!