Want to know about solution to problem related to FaunaDB GraphQL

Hi Team
I have a following GraphQL schema for now

type Tasks{
id
taskname
}

type User{
id
email
tasks: [Task] @relation
}

user contains reference to tasks in an array like

“tasks”: [
Ref(Collection(“task”), “368036611573678284”),
Ref(Collection(“task”), “368036611596746956”)
]

so now I have UDF resolver which returns data from shell based on [id] for user is passed to UDF to fetch user details and tasks for that

type Query {
getSpecificUserWithTask(id:Int!): [User!] @resolver(name: “filterUserwithTask”)
}

when I upload graphql file to GRAPHQL it gives me following error

Target type 'Task' has no field that can be used in the relationship with the type 'User'
tasks: [Task] @relation

can you please guide me what causes the issue.

I have got the understanding that creating relations between type create an collection which keeps the data for relationships keeping reference id for task collection and user collection. so the thing I was trying earlier was not correct.

Hi @Ankit_Arora are you still looking for help?

For many-to-many relationships, this is correct. We have documentation describing how relationships are implemented depending on your GraphQL schema.

One-to-many relationships do not need an intermediate Collection. But you do need to make sure that you define your schema using the @relation directive appropriately for the type of relationship you need.

so that means we need to defined relationship like this

type Tasks{
id
taskname
user: User
}

type User{
id
email
tasks: [Task] @relation
}

so for this one to many relationship user field must be there in type Tasks. what if we want to keep tasks in type User only and not want to keep user inside type Tasks. is that feasible.

like this is one to many relationship and I understood only many to many would require an intermediate table.

Thanks

This schema will put a reference to the User in each Tasks document. An index is then used to fetch all tasks for a given user. e.g.

query {
  findUserByID(id: "101") {
    _id
    email
    tasks {
      # essentially the result of 
      # `Paginate(Match(Index("tasks_user_by_user"), user))`
      data { 
        _id
        taskname
      }
    }
  }
}

No intermediate collection is required, because the relationship is stored directly in one of the collections and accessible either directly or through the index.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.