MCPcopy Index your code
hub / github.com/graphql-java/graphql-java / ConcernsExamples

Class ConcernsExamples

src/test/groovy/readme/ConcernsExamples.java:12–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import static graphql.StarWarsSchema.queryType;
11
12@SuppressWarnings({"unused", "Convert2Lambda"})
13public class ConcernsExamples {
14
15 private GraphQLSchema schema = GraphQLSchema.newSchema()
16 .query(queryType)
17 .build();
18
19
20 private GraphQL buildSchema() {
21 return GraphQL.newGraphQL(schema)
22 .build();
23 }
24
25 private static class User {
26
27 }
28
29 static class YourGraphqlContextBuilder {
30 static UserContext getContextForUser(User user) {
31 return null;
32 }
33 }
34
35 private static class UserContext {
36
37 }
38
39 private User getCurrentUser() {
40 return null;
41 }
42
43
44 private Object invokeBusinessLayerMethod(UserContext userCtx, Long businessObjId) {
45 return null;
46 }
47
48 private GraphQL graphQL = GraphQL.newGraphQL(schema)
49 .build();
50
51 private void contextHelper() {
52 //
53 // this could be code that authorises the user in some way and sets up enough context
54 // that can be used later inside data fetchers allowing them
55 // to do their job
56 //
57 UserContext contextForUser = YourGraphqlContextBuilder.getContextForUser(getCurrentUser());
58
59 ExecutionInput executionInput = ExecutionInput.newExecutionInput()
60 .graphQLContext(context -> context.put("userContext", contextForUser))
61 .build();
62
63 ExecutionResult executionResult = graphQL.execute(executionInput);
64
65 // ...
66 //
67 // later you are able to use this context object when a data fetcher is invoked
68 //
69

Callers

nothing calls this directly

Calls 4

newSchemaMethod · 0.95
newGraphQLMethod · 0.95
buildMethod · 0.65
queryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…