Skip to content

@require_graphql_subschema to manage large schema #54

@Keweiqu

Description

@Keweiqu

As an opposite direction of composite schema, by creating subschemas, we can manage the schema size and have the ability to gradually reveal more parts of the schema to the model as it sees fit. This is inspired by the claude skill. Concrete example below:

1 Entrypoint SDL

Contains the directive and the root fields. Each field is annotated with the subschema(s) it requires. Types referenced here are defined in the subschemas.

# entrypoint.graphql
directive @require_graphql_subschema(names: [String!]!) on FIELD_DEFINITION
type Query {
  # Task queries
  task(id: ID!): Task
    @require_graphql_subschema(names: ["TASK"])
  tasks(first: Int, after: ID): [Task!]!
    @require_graphql_subschema(names: ["TASK"])
  # Calendar queries
  calendarMeeting(id: ID!): CalendarMeeting
    @require_graphql_subschema(names: ["CALENDAR"])
  meetings(start: Int!, end: Int!): [CalendarMeeting!]!
    @require_graphql_subschema(names: ["CALENDAR"])
}
  1. Task subschema SDL
    Defines the Task domain types. No directive usage here—annotation is strictly at fields in the entrypoint or on field selections within objects (if you choose to gate nested fields too).
# task_subschema.graphql
type Task {
  id: ID!
  title: String!
  priority: TaskPriority!
  ownerId: ID
  # If you need nested gating on object fields, you can apply the directive here too.
  # comments: [TaskComment!]! @require_graphql_subschema(names: ["TASK"])
}
enum TaskPriority {
  HIGH
  MID
  LOW
}
type TaskComment {
  id: ID!
  text: String!
  createdAt: Int!
}
  1. Calendar subschema SDL
    Defines calendar domain types. Again, no directive usage here unless you want to gate specific nested fields.
# calendar_subschema.graphql
type CalendarMeeting {
  id: ID!
  title: String!
  startTime: Int!
  endTime: Int!
  attendees: [Employee!]! @require_graphql_subschema(names: ["EMPLOYEE"])
  room: Room
}
type Room {
  id: ID!
  displayName: String!
}

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