Skip to content

Using GraphQlContext to store query metadata #35

@levans002

Description

@levans002

Apologies if this question doesn't belong here..
Imagine the schema:

type School {
    schoolId: String
    schoolName: String
    schoolAddress: Address
    classes: [Class]
}

type Class {
    classId: String
    className: String
    classRoomNumber: Int
    students: [Student]
}

type Student {
    studentId: String
    studentName: String
    grade: Int
}

Is there a way of getting schoolId from within the resolver for Student (without specifying it as a parameter)?

I see that I can get/set on: dataFetchingEnvironment.dataGraphQLContext.subject.publicCredentials to use it as a sort of fetching context to pass things to lower level resolvers.

The issue is this 'subject' is very security specific and I don't want to use it for general purpose key -> value data.

I assume I can create my own implementation of the DataFetchingEnvironment that returns a GraphQLContext wrapper or something, but I wanted to be sure:

  1. This hasn't been done and I just cant find it
  2. This context is per request and thread safe?

I'm assuming I'm missing something about why this is a horrible idea. If it exists for security specific metadata, I would think it would also exist for general data?

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