Spring Boot GraphQL Tutorial #22 - Custom Context

Опубликовано: 29 Октябрь 2024
на канале: Philip Starritt
6,755
63

What is a custom context and why do I need one in graphql?


In graphql spring boot, you have the ability to create a custom object once at the very start of the query/mutation, and this object will be available to all mutations and queries via the DataFetchingEnvironment. The custom object can be any type, and is never used by the internal graphql java framework.


As the context is created once and available in all revolvers; a common use-case to store user authorization data such as user id, permissions and roles. This data can then be used to perform authorization on your mutation and resolvers. An alternative to this is spring security and pass the security context to other threads via DelegatingSecurityContextExecutorService. But the context file can contain anything you wish.


See you in the next video where we use the facebook dataLoaders to solve the N+1 problem!


Cheers!
Philip

Spring Boot GraphQL DataFetchingEnvironment breakdown:    • Spring Boot GraphQL Tutorial #14 - Da...  

Spring Boot GraphQL Java: https://github.com/graphql-java-kicks...


Spring Security DelegatingSecurityContextExecutorService to pass auth data between threads: https://docs.spring.io/spring-securit...


 Thumbnail character vector referenced from freepik: www.freepik.com