Skip to content

Use ancestors as field arguments #144

Closed
@lucaslorentz

Description

@lucaslorentz

Considering the following schema:

Event {
  id: String
  name: String
  speakers: [Speaker]
  talks: [Talk]
}
Speaker {
  id: String
  name: String
  events: [Event]
  talks: [Talk]
}
Talk {
  name: String
  speaker: Speaker
  event: Event
}

I would like to create queries like:

query {
   events {
     name
     speakers {
        name,
        talks {
          name
        }
     }
   }
}

I checked the specs and didn't find any way to filter the speaker's talks by the ancestor event.

I'm using directives on the examples below to demonstrate a feature GraphQL could have:

query {
   events {
     id @into (variable: "$eventId")
     name
     speakers {
        name,
        talks(eventId: $eventId) {
          name
        }
     }
   }
}

That would allow us to completely re-shape the query using the same schema:

query {
   speakers {
     id @into (variable: "$speakerId")
     name
     events {
        name,
        talks(speakerId: $speakerId) {
          id,
          name
        }
     }
   }
}

Or even go further:

query {
   events {
     id @into (variable: "$eventId")
     name
     speakers {
        name,
        talksOnThisEvent: talks(eventId: $eventId) {
          name
        },
        talksOnOtherEvents: talks(excludeEventId: $eventId) {
          name,
          event: {
            name
          }
        }
     }
   }
}

I believe such feature is a nice to have and would decouple even more GraphQL consumers, giving them the ability to completely re-group the data using any entry point: Event, Speaker

Any suggestions/opinions about that?

Related to: #88

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions