| 10 | import static graphql.StarWarsSchema.queryType; |
| 11 | |
| 12 | @SuppressWarnings({"unused", "Convert2Lambda"}) |
| 13 | public 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…