Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many-to-many relationships in Graphiti Schema #141

Open
RoProducts opened this issue Sep 9, 2024 · 2 comments
Open

Many-to-many relationships in Graphiti Schema #141

RoProducts opened this issue Sep 9, 2024 · 2 comments

Comments

@RoProducts
Copy link

RoProducts commented Sep 9, 2024

Hi,

I'm having issues creating a GraphQL schema with Graphiti containing a many-to-many relationship.

The setup is basically this :

let schema = try! Schema<Resolver, Request> {

  Scalar(UUID.self)

    Type(User.self) {
        Field("id", at: \.id)
        [ ... ]
        // Users' groups (many-to-many relationship)
        Field("groups", at: User.getGroups)
    }

    Type(Group.self){
    
        Field("id", at: \.id)
        [ ... ]
        Field("users", at: Group.getUsers)
   }     

   [ ... ]
 
}

I'm getting the error

Fatal error: 'try!' expression unexpectedly raised an error: Cannot use type "Array<Group>" for field "groups". Type does not map to a GraphQL type.

The problem seems that User uses groups before Group is declared. Do you have a sample or some docs I didn't see how to pre-declare types in this scenario ?

Thank you

@cshadek
Copy link
Contributor

cshadek commented Sep 9, 2024

Hi @RoProducts, what is the function signature for User.getGroups()?

@RoProducts
Copy link
Author

The function signature is

   func getGroups(request: Request,arguments: NoArguments) throws -> EventLoopFuture<[Group]> {
        [ ... ]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants