Skip to content

Many-to-many relationships in Graphiti Schema #141

@RoProducts

Description

@RoProducts

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions