Is that possible to use CurrentIdentity() on GraphQL?

Hi folks,

Is that possible to pass the owner id as the user id from the token using graphql? I know that using FQL there is a function CurrentIdentity for that.

mutation {
  createCompany(data: {name: "bosch"}) {
    ownerId // CurrentIdentity()

hi Bruno! I don’t know if the GraphQL API can access these functions yet, but we have a newer version in Preview testing that should work. Would you like to try it out? Either way, you will need a resolver.

1 Like

GraphQL cannot directly call FQL functions. There is no association with a ownerId field and any FQL function.

You can write your own resolver, which is a user-defined function written in FQL that could call CurrentIdentity. For more information, see: @resolver | Fauna Documentation

1 Like

Sure, I would love that.

Thanks @ewan.

I didn’t try yet but, should @resolvers work good with inputs? Like:

input NewProduct {
    ownerId: String! @resolver(name: "currentUserId")

where currentUserId is a UDF:

  name: "currentUserId",
  body: Query(Get('id', CurrentIdentity()))

I would think so, but my GraphQL-fu is weak. I’d have to try it to know.

1 Like

Ohai Bruno! :slight_smile:
It’s one of my deepest wishes for GraphQL to interop with FQL in a more seamless way. I’d love for us to be able to override field resolvers even mid query. I’m pretty sure atm the input resolver is not possible. Would only work on a mutation or query as far as I know. But feel free to try it out, sometimes the Fauna team pushes out so many cool things that I can’t follow :smiley:

1 Like