diff --git a/timbuctoo-instancev4/pom.xml b/timbuctoo-instancev4/pom.xml index 4214a7261e..534da32422 100644 --- a/timbuctoo-instancev4/pom.xml +++ b/timbuctoo-instancev4/pom.xml @@ -265,7 +265,7 @@ com.graphql-java graphql-java - 11.0 + 20.0 diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/datastores/implementations/bdb/BdbSchemaStore.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/datastores/implementations/bdb/BdbSchemaStore.java index 6ab4efdea6..17738d4b3f 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/datastores/implementations/bdb/BdbSchemaStore.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/datastores/implementations/bdb/BdbSchemaStore.java @@ -11,7 +11,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus; import nl.knaw.huygens.timbuctoo.v5.dataset.OptimizedPatchListener; import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType; -import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad; import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction; import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.QuadGraphs; import nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaStore; diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/endpoints/GraphQl.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/endpoints/GraphQl.java index 6bb8a1b2c3..9da60ed5bd 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/endpoints/GraphQl.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/dropwizard/endpoints/GraphQl.java @@ -3,17 +3,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.sleepycat.je.DatabaseException; import graphql.ExecutionResult; import graphql.GraphQL; import graphql.GraphQLException; import graphql.schema.GraphQLSchema; import nl.knaw.huygens.timbuctoo.util.UriHelper; import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository; -import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.RdfProcessingFailedException; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.SerializerWriter; import nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.SerializerWriterRegistry; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData; import nl.knaw.huygens.timbuctoo.v5.graphql.security.PermissionBasedFieldVisibility; import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.graphql.serializable.SerializerExecutionStrategy; @@ -44,7 +41,6 @@ import static graphql.ExecutionInput.newExecutionInput; import static nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn; import static nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO; -import static nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData.contextData; @Path("/v5/graphql") public class GraphQl { @@ -58,8 +54,7 @@ public class GraphQl { public GraphQl(Supplier graphqlGetter, SerializerWriterRegistry serializerWriterRegistry, UserValidator userValidator, UriHelper uriHelper, PermissionFetcher permissionFetcher, - DataSetRepository dataSetRepository) - throws DatabaseException, RdfProcessingFailedException { + DataSetRepository dataSetRepository) { this.graphqlGetter = graphqlGetter; this.serializerWriterRegistry = serializerWriterRegistry; this.userValidator = userValidator; @@ -85,7 +80,7 @@ public Response postJson(JsonNode body, @QueryParam("query") String query, } else { queryFromBody = null; } - Map variables = null; + Map variables = null; if (body.has("variables")) { try { variables = objectMapper.treeToValue(body.get("variables"), HashMap.class); @@ -119,14 +114,13 @@ public Response get(@QueryParam("query") String query, @HeaderParam("accept") St return executeGraphql(null, acceptHeader, acceptParam, query, null, null, authHeader); } - public Response executeGraphql(String query, String acceptHeader, String acceptParam, String queryFromBody, - Map variables, String operationName, String authHeader) { + Map variables, String operationName, String authHeader) { final SerializerWriter serializerWriter; if (acceptParam != null && !acceptParam.isEmpty()) { acceptHeader = acceptParam; //Accept param overrules header because it's more under the user's control } - if (unSpecifiedAcceptHeader(acceptHeader)) { + if (acceptHeader == null || acceptHeader.isEmpty() || "*/*".equals(acceptHeader)) { acceptHeader = MediaType.APPLICATION_JSON; } if (MediaType.APPLICATION_JSON.equals(acceptHeader)) { @@ -166,14 +160,11 @@ public Response executeGraphql(String query, String acceptHeader, String acceptP user = Optional.empty(); } - UserPermissionCheck userPermissionCheck = new UserPermissionCheck( - user, - permissionFetcher - ); - - final GraphQLSchema transform = graphqlGetter - .get() - .transform(b -> b.fieldVisibility(new PermissionBasedFieldVisibility(userPermissionCheck,dataSetRepository))); + final UserPermissionCheck userPermissionCheck = new UserPermissionCheck(user, permissionFetcher); + final GraphQLSchema schema = graphqlGetter.get(); + final GraphQLSchema transform = schema.transform(sb -> + sb.codeRegistry(schema.getCodeRegistry().transform(crb -> + crb.fieldVisibility(new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository))))); final GraphQL.Builder builder = GraphQL.newGraphQL(transform); if (serializerWriter != null) { @@ -185,8 +176,8 @@ public Response executeGraphql(String query, String acceptHeader, String acceptP try { final ExecutionResult result = graphQl .execute(newExecutionInput() - .root(new RootData(user)) - .context(contextData(userPermissionCheck, user)) + .root(new Object()) + .graphQLContext(Map.of("userPermissionCheck", userPermissionCheck, "user", user)) .query(queryFromBody) .operationName(operationName) .variables(variables == null ? Collections.emptyMap() : variables) @@ -219,10 +210,4 @@ public Response executeGraphql(String query, String acceptHeader, String acceptP // throw e; } } - - - public boolean unSpecifiedAcceptHeader(@HeaderParam("accept") String acceptHeader) { - return acceptHeader == null || acceptHeader.isEmpty() || "*/*".equals(acceptHeader); - } - } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/DirectiveRetriever.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/DirectiveRetriever.java index 62ef7bbf6e..7064898a38 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/DirectiveRetriever.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/DirectiveRetriever.java @@ -9,12 +9,11 @@ public class DirectiveRetriever { public static Optional getDirectiveArgument(GraphQLObjectType parentType, String directiveName, String argumentName) { - // if (parentType.getDefinition().getDirectives(directiveName).isEmpty()) { - // return Optional.empty(); - // } + if (parentType.getDefinition().getDirectives(directiveName).isEmpty()) { + return Optional.empty(); + } - // return Optional.of(parentType.getDefinition().getDirectives(directiveName).get(0)) - return Optional.ofNullable(parentType.getDefinition().getDirective(directiveName)) + return Optional.of(parentType.getDefinition().getDirectives(directiveName).get(0)) .map(d -> d.getArgument(argumentName)) .map(v -> (StringValue) v.getValue()) .map(StringValue::getValue); @@ -22,12 +21,11 @@ public static Optional getDirectiveArgument(GraphQLObjectType parentType public static Optional getDirectiveArgument(GraphQLFieldDefinition field, String directiveName, String argumentName) { - // if (field.getDefinition().getDirectives(directiveName).isEmpty()) { - // return Optional.empty(); - // } - // - // return Optional.of(field.getDefinition().getDirectives(directiveName).get(0)) - return Optional.ofNullable(field.getDefinition().getDirective(directiveName)) + if (field.getDefinition().getDirectives(directiveName).isEmpty()) { + return Optional.empty(); + } + + return Optional.of(field.getDefinition().getDirectives(directiveName).get(0)) .map(d -> d.getArgument(argumentName)) .map(v -> (StringValue) v.getValue()) .map(StringValue::getValue); diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataMetaDataListFetcher.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataMetaDataListFetcher.java index b4a8c80fa9..37248d587b 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataMetaDataListFetcher.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataMetaDataListFetcher.java @@ -3,16 +3,15 @@ import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck.OldGraphQlPermission; -import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; +import nl.knaw.huygens.timbuctoo.v5.security.dto.User; +import java.util.Optional; import java.util.stream.Stream; public class DataMetaDataListFetcher implements DataFetcher { - private final DataSetRepository dataSetRepository; public DataMetaDataListFetcher(DataSetRepository dataSetRepository) { @@ -22,20 +21,19 @@ public DataMetaDataListFetcher(DataSetRepository dataSetRepository) { @Override public Object get(DataFetchingEnvironment env) { return (Iterable) () -> { - Stream dataSets = dataSetRepository.getDataSets() - .stream() - .map(dataSet -> new DataSetWithDatabase(dataSet, - ((ContextData) env.getContext()) - .getUserPermissionCheck())); + Stream dataSets = dataSetRepository + .getDataSets() + .stream() + .map(dataSet -> new DataSetWithDatabase(dataSet, env.getGraphQlContext().get("userPermissionCheck"))); if (env.getArgument("ownOnly")) { - String userId = - ((ContextData) env.getContext()).getUser().map(u -> "u" + u.getPersistentId()).orElse(null); + Optional user = env.getGraphQlContext().get("user"); + String userId = user.map(u -> "u" + u.getPersistentId()).orElse(null); dataSets = dataSets.filter(d -> d.getOwnerId().equals(userId)); } // translate OldGraphQlPermission permission = OldGraphQlPermission.valueOf(env.getArgument("permission")); - dataSets = dataSets.filter(d -> ((ContextData) env.getContext()).getUserPermissionCheck() - .hasOldGraphQlPermission(d, permission)); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); + dataSets = dataSets.filter(d -> userPermissionCheck.hasOldGraphQlPermission(d, permission)); return dataSets.iterator(); }; diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataSetImportStatusFetcher.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataSetImportStatusFetcher.java index 60f44b5581..43ca5328ab 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataSetImportStatusFetcher.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/DataSetImportStatusFetcher.java @@ -7,7 +7,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogEntry; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.LogEntryImportStatus; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; @@ -29,11 +28,10 @@ public DataSetImportStatusFetcher(DataSetRepository dataSetRepository) { @Override public List get(DataFetchingEnvironment env) { - User currentUser = env.getContext().getUser() - .orElseThrow(() -> new RuntimeException("You are not logged in")); + Optional user = env.getGraphQlContext().get("user"); + User currentUser = user.orElseThrow(() -> new RuntimeException("You are not logged in")); DataSetMetaData dataSetMetaData = env.getSource(); - MutationHelpers.checkPermission(env, dataSetMetaData, Permission.READ_IMPORT_STATUS); DataSetMetaData input = env.getSource(); @@ -43,16 +41,16 @@ public List get(DataFetchingEnvironment env) { input.getDataSetId() ); - return dataSetOpt.map(dataSet -> dataSet.getImportManager().getLogList()) - .map(logList -> { - final int[] num = new int[]{0}; - return logList.getEntries().stream().map(logEntry -> { - Iterable unprocessedEntries = logList::getUnprocessed; - boolean unprocessed = stream(unprocessedEntries.spliterator(), false) - .anyMatch(unprocessedEntry -> unprocessedEntry.equals(logEntry)); - return new LogEntryImportStatus(logEntry, num[0]++, unprocessed); - }).collect(toList()); - }).orElse(Lists.newArrayList()); + return dataSetOpt + .map(dataSet -> dataSet.getImportManager().getLogList()) + .map(logList -> { + final int[] num = new int[]{0}; + return logList.getEntries().stream().map(logEntry -> { + Iterable unprocessedEntries = logList::getUnprocessed; + boolean unprocessed = stream(unprocessedEntries.spliterator(), false) + .anyMatch(unprocessedEntry -> unprocessedEntry.equals(logEntry)); + return new LogEntryImportStatus(logEntry, num[0]++, unprocessed); + }).collect(toList()); + }).orElse(Lists.newArrayList()); } - } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/ImportStatusFetcher.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/ImportStatusFetcher.java index cab14c8ff4..e642a3f461 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/ImportStatusFetcher.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/ImportStatusFetcher.java @@ -6,7 +6,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.LogEntry; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.LogEntryImportStatus; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.MutationHelpers; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; @@ -26,11 +25,10 @@ public ImportStatusFetcher(DataSetRepository dataSetRepository) { @Override public LogEntryImportStatus get(DataFetchingEnvironment env) { - User currentUser = env.getContext().getUser() - .orElseThrow(() -> new RuntimeException("You are not logged in")); + Optional user = env.getGraphQlContext().get("user"); + User currentUser = user.orElseThrow(() -> new RuntimeException("You are not logged in")); DataSetMetaData dataSetMetaData = env.getSource(); - MutationHelpers.checkPermission(env, dataSetMetaData, Permission.READ_IMPORT_STATUS); Optional dataSetOpt = dataSetRepository.getDataSet( @@ -39,19 +37,19 @@ public LogEntryImportStatus get(DataFetchingEnvironment env) { dataSetMetaData.getDataSetId() ); - return dataSetOpt.map(dataSet -> dataSet.getImportManager().getLogList()) - .map(logList -> { - int id = Integer.parseInt(env.getArgument("id")); - List entries = logList.getEntries(); - if (entries.size() > id) { - LogEntry logEntry = logList.getEntries().get(id); - Iterable unprocessedEntries = logList::getUnprocessed; - boolean unprocessed = stream(unprocessedEntries.spliterator(), false) - .anyMatch(unprocessedEntry -> unprocessedEntry.equals(logEntry)); - return new LogEntryImportStatus(logEntry, id, unprocessed); - } - return null; - }).orElseThrow(() -> new RuntimeException("No import status with id: " + env.getArgument("id"))); - + return dataSetOpt + .map(dataSet -> dataSet.getImportManager().getLogList()) + .map(logList -> { + int id = Integer.parseInt(env.getArgument("id")); + List entries = logList.getEntries(); + if (entries.size() > id) { + LogEntry logEntry = logList.getEntries().get(id); + Iterable unprocessedEntries = logList::getUnprocessed; + boolean unprocessed = stream(unprocessedEntries.spliterator(), false) + .anyMatch(unprocessedEntry -> unprocessedEntry.equals(logEntry)); + return new LogEntryImportStatus(logEntry, id, unprocessed); + } + return null; + }).orElseThrow(() -> new RuntimeException("No import status with id: " + env.getArgument("id"))); } } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/OtherDataSetFetcher.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/OtherDataSetFetcher.java index 7b8b5bb2f3..61bb1a963a 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/OtherDataSetFetcher.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/OtherDataSetFetcher.java @@ -8,10 +8,10 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.dto.LazyTypeSubjectReference; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectGraphReference; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; +import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import java.util.HashSet; import java.util.List; @@ -24,7 +24,6 @@ import static nl.knaw.huygens.timbuctoo.util.Tuple.tuple; public class OtherDataSetFetcher implements DataFetcher> { - private final DataSetRepository repo; public OtherDataSetFetcher(DataSetRepository repo) { @@ -34,15 +33,16 @@ public OtherDataSetFetcher(DataSetRepository repo) { @Override public List get(DataFetchingEnvironment env) { if (env.getSource() instanceof SubjectGraphReference) { - final Set dataSetIds = new HashSet<>(); SubjectGraphReference source = env.getSource(); - ContextData contextData = env.getContext(); - Stream dataSets = contextData.getUser() + Optional optUser = env.getGraphQlContext().get("user"); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); + + Stream dataSets = optUser .map(user -> repo.getDataSetsWithReadAccess(user).stream()) .orElseGet(() -> repo.getDataSets().stream().filter(d -> d.getMetadata().isPublished())); if (env.containsArgument("dataSetIds")) { - dataSetIds.addAll(env.getArgument("dataSetIds")); + final Set dataSetIds = new HashSet<>(env.getArgument("dataSetIds")); dataSets = dataSets.filter(d -> dataSetIds.contains(d.getMetadata().getCombinedId())); } final String ownId = source.getDataSet().getMetadata().getCombinedId(); @@ -55,13 +55,11 @@ public List get(DataFetchingEnvironment env) { }) .filter(i -> i.getRight().isPresent()) .map(i -> ImmutableMap.of( - "metadata", new DataSetWithDatabase(i.getLeft(), env.getContext().getUserPermissionCheck()), + "metadata", new DataSetWithDatabase(i.getLeft(), userPermissionCheck), "entity", new LazyTypeSubjectReference(i.getRight().get().getSubject(), source.getGraph(), i.getLeft()) )) .collect(toList()); - } return Lists.newArrayList(); } - } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/RdfWiringFactory.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/RdfWiringFactory.java index 34d9bc8c9b..2e35cc14a1 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/RdfWiringFactory.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/RdfWiringFactory.java @@ -112,34 +112,34 @@ public TypeResolver getTypeResolver(UnionWiringEnvironment environment) { @Override public boolean providesDataFetcher(FieldWiringEnvironment environment) { - return environment.getFieldDefinition().getDirective("fromCollection") != null || - environment.getFieldDefinition().getDirective("lookupUri") != null || - environment.getFieldDefinition().getDirective("rdf") != null || - environment.getFieldDefinition().getDirective("uri") != null || - environment.getFieldDefinition().getDirective("graphs") != null || - environment.getFieldDefinition().getDirective("passThrough") != null || - environment.getFieldDefinition().getDirective("related") != null || - environment.getFieldDefinition().getDirective("dataSet") != null || - environment.getFieldDefinition().getDirective("entityTitle") != null || - environment.getFieldDefinition().getDirective("entityDescription") != null || - environment.getFieldDefinition().getDirective("entityImage") != null || - environment.getFieldDefinition().getDirective("otherDataSets") != null || - environment.getFieldDefinition().getDirective("getAllOfPredicate") != null || - environment.getFieldDefinition().getDirective("createMutation") != null || - environment.getFieldDefinition().getDirective("editMutation") != null || - environment.getFieldDefinition().getDirective("deleteMutation") != null || - environment.getFieldDefinition().getDirective("persistEntityMutation") != null || - environment.getFieldDefinition().getDirective("setCustomProvenanceMutation") != null || - environment.getFieldDefinition().getDirective("resetIndex") != null || - environment.getFieldDefinition().getDirective("oldItems") != null; + return !environment.getFieldDefinition().getDirectives("fromCollection").isEmpty() || + !environment.getFieldDefinition().getDirectives("lookupUri").isEmpty() || + !environment.getFieldDefinition().getDirectives("rdf").isEmpty() || + !environment.getFieldDefinition().getDirectives("uri").isEmpty() || + !environment.getFieldDefinition().getDirectives("graphs").isEmpty() || + !environment.getFieldDefinition().getDirectives("passThrough").isEmpty() || + !environment.getFieldDefinition().getDirectives("related").isEmpty() || + !environment.getFieldDefinition().getDirectives("dataSet").isEmpty() || + !environment.getFieldDefinition().getDirectives("entityTitle").isEmpty() || + !environment.getFieldDefinition().getDirectives("entityDescription").isEmpty() || + !environment.getFieldDefinition().getDirectives("entityImage").isEmpty() || + !environment.getFieldDefinition().getDirectives("otherDataSets").isEmpty() || + !environment.getFieldDefinition().getDirectives("getAllOfPredicate").isEmpty() || + !environment.getFieldDefinition().getDirectives("createMutation").isEmpty() || + !environment.getFieldDefinition().getDirectives("editMutation").isEmpty() || + !environment.getFieldDefinition().getDirectives("deleteMutation").isEmpty() || + !environment.getFieldDefinition().getDirectives("persistEntityMutation").isEmpty() || + !environment.getFieldDefinition().getDirectives("setCustomProvenanceMutation").isEmpty() || + !environment.getFieldDefinition().getDirectives("resetIndex").isEmpty() || + !environment.getFieldDefinition().getDirectives("oldItems").isEmpty(); } @Override public DataFetcher getDataFetcher(FieldWiringEnvironment environment) { - if (environment.getFieldDefinition().getDirective("passThrough") != null) { + if (!environment.getFieldDefinition().getDirectives("passThrough").isEmpty()) { return DataFetchingEnvironment::getSource; - } else if (environment.getFieldDefinition().getDirective("related") != null) { - final Directive directive = environment.getFieldDefinition().getDirective("related"); + } else if (!environment.getFieldDefinition().getDirectives("related").isEmpty()) { + final Directive directive = environment.getFieldDefinition().getDirectives("related").get(0); String source = ((StringValue) directive.getArgument("source").getValue()).getValue(); String predicate = ((StringValue) directive.getArgument("predicate").getValue()).getValue(); String direction = ((StringValue) directive.getArgument("direction").getValue()).getValue(); @@ -148,14 +148,14 @@ public DataFetcher getDataFetcher(FieldWiringEnvironment environment) { predicate, Direction.valueOf(direction) )); - } else if (environment.getFieldDefinition().getDirective("lookupUri") != null) { + } else if (!environment.getFieldDefinition().getDirectives("lookupUri").isEmpty()) { return lookupFetcher; - } else if (environment.getFieldDefinition().getDirective("fromCollection") != null) { - final Directive directive = environment.getFieldDefinition().getDirective("fromCollection"); + } else if (!environment.getFieldDefinition().getDirectives("fromCollection").isEmpty()) { + final Directive directive = environment.getFieldDefinition().getDirectives("fromCollection").get(0); String uri = ((StringValue) directive.getArgument("uri").getValue()).getValue(); return new CollectionFetcherWrapper(argumentsHelper, new CollectionDataFetcher(uri)); - } else if (environment.getFieldDefinition().getDirective("rdf") != null) { - final Directive directive = environment.getFieldDefinition().getDirective("rdf"); + } else if (!environment.getFieldDefinition().getDirectives("rdf").isEmpty()) { + final Directive directive = environment.getFieldDefinition().getDirectives("rdf").get(0); String uri = ((StringValue) directive.getArgument("predicate").getValue()).getValue(); Direction direction = valueOf(((StringValue) directive.getArgument("direction").getValue()).getValue()); boolean isList = ((BooleanValue) directive.getArgument("isList").getValue()).isValue(); @@ -170,29 +170,29 @@ public DataFetcher getDataFetcher(FieldWiringEnvironment environment) { return new DataFetcherWrapper(argumentsHelper, isList, new TypedLiteralDataFetcher(uri)); } } - } else if (environment.getFieldDefinition().getDirective("uri") != null) { + } else if (!environment.getFieldDefinition().getDirectives("uri").isEmpty()) { return uriFetcher; - } else if (environment.getFieldDefinition().getDirective("graphs") != null) { + } else if (!environment.getFieldDefinition().getDirectives("graphs").isEmpty()) { return graphsFetcher; - } else if (environment.getFieldDefinition().getDirective("dataSet") != null) { - final Directive directive = environment.getFieldDefinition().getDirective("dataSet"); + } else if (!environment.getFieldDefinition().getDirectives("dataSet").isEmpty()) { + final Directive directive = environment.getFieldDefinition().getDirectives("dataSet").get(0); String userId = ((StringValue) directive.getArgument("userId").getValue()).getValue(); String dataSetId = ((StringValue) directive.getArgument("dataSetId").getValue()).getValue(); final DataSet dataSet = dataSetRepository.unsafeGetDataSetWithoutCheckingPermissions(userId, dataSetId) .orElse(null); return dataFetchingEnvironment -> (DatabaseResult) () -> dataSet; - } else if (environment.getFieldDefinition().getDirective("entityTitle") != null) { + } else if (!environment.getFieldDefinition().getDirectives("entityTitle").isEmpty()) { return entityTitleFetcher; - } else if (environment.getFieldDefinition().getDirective("entityDescription") != null) { + } else if (!environment.getFieldDefinition().getDirectives("entityDescription").isEmpty()) { return entityDescriptionFetcher; - } else if (environment.getFieldDefinition().getDirective("entityImage") != null) { + } else if (!environment.getFieldDefinition().getDirectives("entityImage").isEmpty()) { return entityImageFetcher; - } else if (environment.getFieldDefinition().getDirective("otherDataSets") != null) { + } else if (!environment.getFieldDefinition().getDirectives("otherDataSets").isEmpty()) { return otherDataSetFetcher; - } else if (environment.getFieldDefinition().getDirective("getAllOfPredicate") != null) { + } else if (!environment.getFieldDefinition().getDirectives("getAllOfPredicate").isEmpty()) { return dynamicRelationDataFetcher; - } else if (environment.getFieldDefinition().getDirective("createMutation") != null) { - Directive directive = environment.getFieldDefinition().getDirective("createMutation"); + } else if (!environment.getFieldDefinition().getDirectives("createMutation").isEmpty()) { + Directive directive = environment.getFieldDefinition().getDirectives("createMutation").get(0); StringValue dataSet = (StringValue) directive.getArgument("dataSet").getValue(); StringValue typeUri = (StringValue) directive.getArgument("typeUri").getValue(); @@ -207,37 +207,37 @@ public DataFetcher getDataFetcher(FieldWiringEnvironment environment) { dataSetName, typeUriName )); - } else if (environment.getFieldDefinition().getDirective("editMutation") != null) { - Directive directive = environment.getFieldDefinition().getDirective("editMutation"); + } else if (!environment.getFieldDefinition().getDirectives("editMutation").isEmpty()) { + Directive directive = environment.getFieldDefinition().getDirectives("editMutation").get(0); StringValue dataSet = (StringValue) directive.getArgument("dataSet").getValue(); String dataSetName = dataSet.getValue(); return editMutationMap.computeIfAbsent(dataSetName, s -> new EditMutation(schemaUpdater, dataSetRepository, uriHelper, subjectFetcher, dataSetName)); - } else if (environment.getFieldDefinition().getDirective("deleteMutation") != null) { - Directive directive = environment.getFieldDefinition().getDirective("deleteMutation"); + } else if (!environment.getFieldDefinition().getDirectives("deleteMutation").isEmpty()) { + Directive directive = environment.getFieldDefinition().getDirectives("deleteMutation").get(0); StringValue dataSet = (StringValue) directive.getArgument("dataSet").getValue(); String dataSetName = dataSet.getValue(); return deleteMutationMap.computeIfAbsent(dataSetName, s -> new DeleteMutation(schemaUpdater, dataSetRepository, uriHelper, dataSetName)); - } else if (environment.getFieldDefinition().getDirective("persistEntityMutation") != null) { - Directive directive = environment.getFieldDefinition().getDirective("persistEntityMutation"); + } else if (!environment.getFieldDefinition().getDirectives("persistEntityMutation").isEmpty()) { + Directive directive = environment.getFieldDefinition().getDirectives("persistEntityMutation").get(0); StringValue dataSet = (StringValue) directive.getArgument("dataSet").getValue(); String dataSetName = dataSet.getValue(); return new PersistEntityMutation(schemaUpdater, redirectionService, dataSetName, uriHelper); - } else if (environment.getFieldDefinition().getDirective("setCustomProvenanceMutation") != null) { - Directive directive = environment.getFieldDefinition().getDirective("setCustomProvenanceMutation"); + } else if (!environment.getFieldDefinition().getDirectives("setCustomProvenanceMutation").isEmpty()) { + Directive directive = environment.getFieldDefinition().getDirectives("setCustomProvenanceMutation").get(0); StringValue dataSet = (StringValue) directive.getArgument("dataSet").getValue(); String dataSetId = dataSet.getValue(); return new SetCustomProvenanceMutation(schemaUpdater, dataSetRepository, dataSetId); - } else if (environment.getFieldDefinition().getDirective("resetIndex") != null) { - final Directive resetIndex = environment.getFieldDefinition().getDirective("resetIndex"); + } else if (!environment.getFieldDefinition().getDirectives("resetIndex").isEmpty()) { + final Directive resetIndex = environment.getFieldDefinition().getDirectives("resetIndex").get(0); final StringValue dataSet = (StringValue) resetIndex.getArgument("dataSet").getValue(); return new DefaultIndexConfigMutation(schemaUpdater, dataSetRepository, dataSet.getValue()); - } else if (environment.getFieldDefinition().getDirective("oldItems") != null) { + } else if (!environment.getFieldDefinition().getDirectives("oldItems").isEmpty()) { return oldItemsDataFetcher; } return null; @@ -274,8 +274,7 @@ public GraphQLObjectType getType(TypeResolutionEnvironment environment) { typeName = prefix + "_" + typeNameStore.makeGraphQlname(RDFS_RESOURCE); } else { typeName = null; - // for (Selection selection : environment.getField().getSingleField().getSelectionSet().getSelections()) { - for (Selection selection : environment.getField().getSelectionSet().getSelections()) { + for (Selection selection : environment.getField().getSingleField().getSelectionSet().getSelections()) { if (selection instanceof InlineFragment) { InlineFragment fragment = (InlineFragment) selection; final String typeConditionName = fragment.getTypeCondition().getName(); diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/berkeleydb/datafetchers/GraphsDataFetcher.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/berkeleydb/datafetchers/GraphsDataFetcher.java index f0ac56f7bb..70a8588844 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/berkeleydb/datafetchers/GraphsDataFetcher.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/berkeleydb/datafetchers/GraphsDataFetcher.java @@ -8,7 +8,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.CursorUri; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.PaginationArgumentsHelper; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.PaginatedList; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.PaginationArguments; import nl.knaw.huygens.timbuctoo.v5.graphql.rootquery.dataproviders.StringList; @@ -30,7 +29,7 @@ public GraphsDataFetcher(DataSetRepository dataSetRepository) { public StringList get(DataFetchingEnvironment environment) { if (environment.getSource() instanceof DataSetMetaData) { final DataSetMetaData input = environment.getSource(); - final Optional userOpt = ((ContextData) environment.getContext()).getUser(); + final Optional userOpt = environment.getGraphQlContext().get("user"); final User user = userOpt.orElse(null); final DataSet dataSet = dataSetRepository.getDataSet(user, input.getOwnerId(), input.getDataSetId()).get(); diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/ContextData.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/ContextData.java deleted file mode 100644 index 0cd4d919f7..0000000000 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/ContextData.java +++ /dev/null @@ -1,19 +0,0 @@ -package nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto; - -import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; -import nl.knaw.huygens.timbuctoo.v5.security.dto.User; -import org.immutables.value.Value; - -import java.util.Optional; - -@Value.Immutable -public interface ContextData { - - UserPermissionCheck getUserPermissionCheck(); - - Optional getUser(); - - static ContextData contextData(UserPermissionCheck userPermissionCheck, Optional user) { - return ImmutableContextData.builder().userPermissionCheck(userPermissionCheck).user(user).build(); - } -} diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/RootData.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/RootData.java deleted file mode 100644 index 1084b9080d..0000000000 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/dto/RootData.java +++ /dev/null @@ -1,17 +0,0 @@ -package nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto; - -import nl.knaw.huygens.timbuctoo.v5.security.dto.User; - -import java.util.Optional; - -public class RootData { - public Optional getCurrentUser() { - return currentUser; - } - - private final Optional currentUser; - - public RootData(Optional currentUser) { - this.currentUser = currentUser; - } -} diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateDataSetMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateDataSetMutation.java index 24357ce603..fe7e31c753 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateDataSetMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateDataSetMutation.java @@ -5,7 +5,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetCreationException; import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException; import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.IllegalDataSetNameException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import org.slf4j.Logger; @@ -35,7 +34,7 @@ public Object executeAction(DataFetchingEnvironment env) { try { return new DataSetWithDatabase( dataSetRepository.createDataSet(currentUser, dataSetName, Optional.ofNullable(baseUri)), - env.getContext().getUserPermissionCheck() + env.getGraphQlContext().get("userPermissionCheck") ); } catch (DataStoreCreationException e) { LOG.error("Data set creation exception", e); diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateMutation.java index f27d13317a..e2a4538581 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/CreateMutation.java @@ -11,8 +11,8 @@ import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.QuadStoreLookUpSubjectByUriFetcher; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CreateMutationChangeLog; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import nl.knaw.huygens.timbuctoo.v5.util.Graph; @@ -48,20 +48,21 @@ public Object executeAction(DataFetchingEnvironment environment) { final Graph graph = new Graph(environment.getArgument("graph")); final String uri = environment.getArgument("uri"); final Map entity = environment.getArgument("entity"); - ImmutableContextData contextData = environment.getContext(); - Optional userOpt = contextData.getUser(); - if (!userOpt.isPresent()) { + + Optional userOpt = environment.getGraphQlContext().get("user"); + if (userOpt.isEmpty()) { throw new RuntimeException("User should be logged in."); } User user = userOpt.get(); Optional dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName); - if (!dataSetOpt.isPresent()) { + if (dataSetOpt.isEmpty()) { throw new RuntimeException("Data set is not available."); } DataSet dataSet = dataSetOpt.get(); - if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.CREATE)) { + UserPermissionCheck userPermissionCheck = environment.getGraphQlContext().get("userPermissionCheck"); + if (!userPermissionCheck.hasPermission(dataSet.getMetadata(), Permission.CREATE)) { throw new RuntimeException("User should have permissions to create entities of the data set."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DataSetMetadataMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DataSetMetadataMutation.java index c849c0a632..d38c6a71f5 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DataSetMetadataMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DataSetMetadataMutation.java @@ -9,10 +9,10 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.SimpleMetadataProp; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.UriMetadataProp; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation.MutationOperation; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import java.util.List; @@ -42,6 +42,7 @@ public DataSetMetadataMutation(Runnable schemaUpdater, DataSetRepository dataSet @Override public Object executeAction(DataFetchingEnvironment env) { DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); MutationHelpers.checkPermission(env, dataSet.getMetadata(), Permission.EDIT_DATASET_METADATA); try { @@ -57,7 +58,7 @@ public Object executeAction(DataFetchingEnvironment env) { addMutation(dataSet, new PredicateMutation().entity(baseUri, mutationOperations)); - return new DataSetWithDatabase(dataSet, env.getContext().getUserPermissionCheck()); + return new DataSetWithDatabase(dataSet, userPermissionCheck); } catch (LogStorageFailedException | InterruptedException | ExecutionException e) { throw new RuntimeException(e); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DefaultIndexConfigMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DefaultIndexConfigMutation.java index 1d1c2765d4..25b2d2877b 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DefaultIndexConfigMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DefaultIndexConfigMutation.java @@ -10,8 +10,8 @@ import nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore; import nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; @@ -23,7 +23,7 @@ import static nl.knaw.huygens.timbuctoo.v5.util.RdfConstants.TIM_HASINDEXERCONFIG; public class DefaultIndexConfigMutation extends Mutation { - private static String INDEX_TITLE = "{\n" + + private static final String INDEX_TITLE = "{\n" + "\t\"facet\": [],\n" + "\t\"fullText\": [{\n" + "\t\t\"fields\": [{\n" + @@ -47,13 +47,13 @@ public DefaultIndexConfigMutation(Runnable schemaUpdater, DataSetRepository data protected Object executeAction(DataFetchingEnvironment env) { final User user = MutationHelpers.getUser(env); Optional dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName); - if (!dataSetOpt.isPresent()) { + if (dataSetOpt.isEmpty()) { throw new RuntimeException("Dataset does not exist"); } final DataSet dataSet = dataSetOpt.get(); - ImmutableContextData contextData = env.getContext(); - if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.CONFIG_INDEX)) { + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); + if (!userPermissionCheck.hasPermission(dataSet.getMetadata(), Permission.CONFIG_INDEX)) { throw new RuntimeException("User has no permissions to change the index configuration."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DeleteMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DeleteMutation.java index 89e43b67cb..733401bcaf 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DeleteMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/DeleteMutation.java @@ -10,8 +10,8 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.DeleteMutationChangeLog; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import nl.knaw.huygens.timbuctoo.v5.util.Graph; @@ -42,20 +42,21 @@ public Object executeAction(DataFetchingEnvironment environment) { final Graph graph = new Graph(environment.getArgument("graph")); final String uri = environment.getArgument("uri"); final Map entity = environment.getArgument("entity"); - ImmutableContextData contextData = environment.getContext(); - Optional userOpt = contextData.getUser(); - if (!userOpt.isPresent()) { + + Optional userOpt = environment.getGraphQlContext().get("user"); + if (userOpt.isEmpty()) { throw new RuntimeException("User should be logged in."); } User user = userOpt.get(); Optional dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName); - if (!dataSetOpt.isPresent()) { + if (dataSetOpt.isEmpty()) { throw new RuntimeException("Data set is not available."); } DataSet dataSet = dataSetOpt.get(); - if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.DELETE)) { + UserPermissionCheck userPermissionCheck = environment.getGraphQlContext().get("userPermissionCheck"); + if (!userPermissionCheck.hasPermission(dataSet.getMetadata(), Permission.DELETE)) { throw new RuntimeException("User should have permissions to delete entities of the data set."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/EditMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/EditMutation.java index 01b754f941..9b0782591e 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/EditMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/EditMutation.java @@ -11,8 +11,8 @@ import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.QuadStoreLookUpSubjectByUriFetcher; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import nl.knaw.huygens.timbuctoo.v5.util.Graph; @@ -46,20 +46,21 @@ public Object executeAction(DataFetchingEnvironment environment) { final Graph graph = new Graph(environment.getArgument("graph")); final String uri = environment.getArgument("uri"); final Map entity = environment.getArgument("entity"); - ImmutableContextData contextData = environment.getContext(); - Optional userOpt = contextData.getUser(); - if (!userOpt.isPresent()) { + + Optional userOpt = environment.getGraphQlContext().get("user"); + if (userOpt.isEmpty()) { throw new RuntimeException("User should be logged in."); } User user = userOpt.get(); Optional dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName); - if (!dataSetOpt.isPresent()) { + if (dataSetOpt.isEmpty()) { throw new RuntimeException("Data set is not available."); } DataSet dataSet = dataSetOpt.get(); - if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.WRITE)) { + UserPermissionCheck userPermissionCheck = environment.getGraphQlContext().get("userPermissionCheck"); + if (!userPermissionCheck.hasPermission(dataSet.getMetadata(), Permission.WRITE)) { throw new RuntimeException("User should have permissions to edit entities of the data set."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MakePublicMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MakePublicMutation.java index c3d4277f04..35838aa990 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MakePublicMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MakePublicMutation.java @@ -4,8 +4,8 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataSetPublishException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,12 +19,11 @@ public MakePublicMutation(Runnable schemaUpdater, DataSetRepository dataSetRepos this.dataSetRepository = dataSetRepository; } - @Override public Object executeAction(DataFetchingEnvironment env) { User user = MutationHelpers.getUser(env); - DataSet dataSet = MutationHelpers.getDataSet(env, dataSetRepository::getDataSet); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); try { dataSetRepository.publishDataSet(user, dataSet.getMetadata().getOwnerId(), dataSet.getMetadata().getDataSetId()); @@ -32,6 +31,7 @@ public Object executeAction(DataFetchingEnvironment env) { LOG.error("Failed to publish data set", e); throw new RuntimeException("Failed to publish data set"); } - return new DataSetWithDatabase(dataSet, env.getContext().getUserPermissionCheck()); + + return new DataSetWithDatabase(dataSet, userPermissionCheck); } } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MutationHelpers.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MutationHelpers.java index 0fb65d2b2b..25438fe686 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MutationHelpers.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/MutationHelpers.java @@ -5,7 +5,6 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; import nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation; import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; @@ -16,17 +15,13 @@ public class MutationHelpers { public static User getUser(DataFetchingEnvironment env) { - ContextData contextData = env.getContext(); - - return contextData.getUser().orElseThrow(() -> new RuntimeException("You are not logged in")); + Optional user = env.getGraphQlContext().get("user"); + return user.orElseThrow(() -> new RuntimeException("You are not logged in")); } public static void checkPermission(DataFetchingEnvironment env, DataSetMetaData dataSetMetaData, - Permission permission) - throws RuntimeException { - ContextData contextData = env.getContext(); - - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); + Permission permission) throws RuntimeException { + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); if (!userPermissionCheck.hasPermission(dataSetMetaData, permission)) { throw new RuntimeException("You do not have permission '" + permission + "' for this data set."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/SetCustomProvenanceMutation.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/SetCustomProvenanceMutation.java index b4bc9d9dbe..3d154d260b 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/SetCustomProvenanceMutation.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/mutations/SetCustomProvenanceMutation.java @@ -8,8 +8,8 @@ import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet; import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ImmutableContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance; +import nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck; import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import nl.knaw.huygens.timbuctoo.v5.security.dto.User; @@ -33,19 +33,19 @@ public SetCustomProvenanceMutation(Runnable schemaUpdater, DataSetRepository dat @Override public Object executeAction(DataFetchingEnvironment environment) { - ImmutableContextData contextData = environment.getContext(); - Optional userOpt = contextData.getUser(); - if (!userOpt.isPresent()) { + Optional userOpt = environment.getGraphQlContext().get("user"); + if (userOpt.isEmpty()) { throw new RuntimeException("User should be logged in."); } User user = userOpt.get(); Optional dataSetOpt = dataSetRepository.getDataSet(user, ownerId, dataSetName); - if (!dataSetOpt.isPresent()) { + if (dataSetOpt.isEmpty()) { throw new RuntimeException("Data set is not available."); } DataSet dataSet = dataSetOpt.get(); - if (!contextData.getUserPermissionCheck().hasPermission(dataSet.getMetadata(), Permission.SET_CUSTOM_PROV)) { + UserPermissionCheck userPermissionCheck = environment.getGraphQlContext().get("userPermissionCheck"); + if (!userPermissionCheck.hasPermission(dataSet.getMetadata(), Permission.SET_CUSTOM_PROV)) { throw new RuntimeException("User should have permissions to set the custom provenance."); } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/rootquery/RootQuery.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/rootquery/RootQuery.java index 46bd67f662..dacc1a2f6b 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/rootquery/RootQuery.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/rootquery/RootQuery.java @@ -32,9 +32,7 @@ import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.RdfWiringFactory; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.SummaryPropertiesDataFetcher; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.berkeleydb.datafetchers.GraphsDataFetcher; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.ContextData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DataSetWithDatabase; -import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData; import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference; import nl.knaw.huygens.timbuctoo.v5.graphql.derivedschema.DerivedSchemaContainer; import nl.knaw.huygens.timbuctoo.v5.graphql.derivedschema.DerivedSchemaGenerator; @@ -161,44 +159,41 @@ private GraphQLSchema generateSchema() { .dataFetcher("promotedDataSets", env -> dataSetRepository.getPromotedDataSets() .stream() .map(dataSet -> { - ContextData contextData = env.getContext(); - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); return new DataSetWithDatabase(dataSet, userPermissionCheck); }) .collect(Collectors.toList())) .dataFetcher("allDataSets", env -> dataSetRepository.getDataSets() .stream() .map(dataSet -> { - ContextData contextData = env.getContext(); - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); return new DataSetWithDatabase(dataSet, userPermissionCheck); }) .filter(x -> { if (x.isPublished()) { return true; } else { - ContextData contextData = env.getContext(); - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); return userPermissionCheck.hasPermission(x.getDataSet().getMetadata(), Permission.READ); } }) .collect(Collectors.toList())) .dataFetcher("dataSetMetadata", env -> { final String dataSetId = env.getArgument("dataSetId"); - ContextData context = env.getContext(); - final User user = context.getUser().orElse(null); + final Optional optUser = env.getGraphQlContext().get("user"); + final User user = optUser.orElse(null); Tuple splitCombinedId = DataSetMetaData.splitCombinedId(dataSetId); - return dataSetRepository.getDataSet(user, splitCombinedId.getLeft(), splitCombinedId.getRight()) - .map(dataSet -> { - ContextData contextData = env.getContext(); - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); - return new DataSetWithDatabase(dataSet, userPermissionCheck); - }); + return dataSetRepository + .getDataSet(user, splitCombinedId.getLeft(), splitCombinedId.getRight()) + .map(dataSet -> { + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); + return new DataSetWithDatabase(dataSet, userPermissionCheck); + }); }) .dataFetcher("dataSetMetadataList", env -> { - UserPermissionCheck userPermissionCheck = ((ContextData) env.getContext()).getUserPermissionCheck(); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); Stream dataSets = dataSetRepository.getDataSets() .stream() .map(dataSet -> new DataSetWithDatabase(dataSet, userPermissionCheck)); @@ -212,7 +207,10 @@ private GraphQLSchema generateSchema() { .filter(x -> userPermissionCheck.hasPermission(x.getDataSet().getMetadata(), Permission.READ)) .collect(Collectors.toList()); }) - .dataFetcher("aboutMe", env -> ((RootData) env.getRoot()).getCurrentUser().orElse(null)) + .dataFetcher("aboutMe", env -> { + final Optional optUser = env.getGraphQlContext().get("user"); + return optUser.orElse(null); + }) .dataFetcher("availableExportMimetypes", env -> supportedFormats.getSupportedMimeTypes().stream() .map(MimeTypeDescription::create) .collect(Collectors.toList()) @@ -230,7 +228,10 @@ private GraphQLSchema generateSchema() { .build() ).collect(Collectors.toList())) .dataFetcher("graphs", new GraphsDataFetcher(dataSetRepository)) - .dataFetcher("collectionList", env -> getCollections(env.getSource(), ((ContextData) env.getContext()).getUser())) + .dataFetcher("collectionList", env -> { + final Optional optUser = env.getGraphQlContext().get("user"); + return getCollections(env.getSource(), optUser); + }) .dataFetcher("collection", env -> { String collectionId = (String) env.getArguments().get("collectionId"); if (collectionId != null && collectionId.endsWith("List")) { @@ -286,8 +287,7 @@ private GraphQLSchema generateSchema() { .dataFetcher("dataSets", env -> (Iterable) () -> dataSetRepository .getDataSetsWithWriteAccess(env.getSource()) .stream().map(dataSet -> { - ContextData contextData = env.getContext(); - UserPermissionCheck userPermissionCheck = contextData.getUserPermissionCheck(); + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); return new DataSetWithDatabase(dataSet, userPermissionCheck); }).iterator() ) @@ -358,10 +358,10 @@ private GraphQLSchema generateSchema() { .append(dataSetMetaData.getDataSetId()) .append("\")\n"); - wiring.type(name, c -> c - .dataFetcher("metadata", env -> - new DataSetWithDatabase(dataSet, env.getContext().getUserPermissionCheck())) - ); + wiring.type(name, c -> c.dataFetcher("metadata", env -> { + UserPermissionCheck userPermissionCheck = env.getGraphQlContext().get("userPermissionCheck"); + return new DataSetWithDatabase(dataSet, userPermissionCheck); + })); final DerivedSchemaContainer schema = typeGenerator.makeGraphQlTypes( name, @@ -489,8 +489,7 @@ public GraphQLSchema get() { private DataSet getDataSet(DataFetchingEnvironment env) { DataSetMetaData input = env.getSource(); - ContextData context = env.getContext(); - final User user = context.getUser().orElse(null); - return dataSetRepository.getDataSet(user, input.getOwnerId(), input.getDataSetId()).get(); + final Optional userOpt = env.getGraphQlContext().get("user"); + return dataSetRepository.getDataSet(userOpt.orElse(null), input.getOwnerId(), input.getDataSetId()).get(); } } diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/security/PermissionBasedFieldVisibility.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/security/PermissionBasedFieldVisibility.java index 7804cc855a..43255682dc 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/security/PermissionBasedFieldVisibility.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/graphql/security/PermissionBasedFieldVisibility.java @@ -7,19 +7,14 @@ import nl.knaw.huygens.timbuctoo.v5.security.dto.Permission; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; public class PermissionBasedFieldVisibility implements GraphqlFieldVisibility { - private final UserPermissionCheck userPermissionCheck; - private final DataSetRepository dataSetRepository; - private Set dataSetNamesWithOutReadPermission; + private final Set dataSetNamesWithOutReadPermission; public PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, DataSetRepository dataSetRepository) { - this.userPermissionCheck = userPermissionCheck; - this.dataSetRepository = dataSetRepository; dataSetNamesWithOutReadPermission = dataSetRepository .getDataSets() .stream() @@ -31,37 +26,22 @@ public PermissionBasedFieldVisibility(UserPermissionCheck userPermissionCheck, D @Override public List getFieldDefinitions(GraphQLFieldsContainer fieldsContainer) { List graphQlFieldDefinitions = new ArrayList<>(); - - Iterator graphQlFieldDefinitionIterator = - fieldsContainer.getFieldDefinitions().iterator(); - while (graphQlFieldDefinitionIterator.hasNext()) { - GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); + for (GraphQLFieldDefinition graphQlFieldDefinition : fieldsContainer.getFieldDefinitions()) { if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName())) { graphQlFieldDefinitions.add(graphQlFieldDefinition); } } - return graphQlFieldDefinitions; } @Override public GraphQLFieldDefinition getFieldDefinition(GraphQLFieldsContainer fieldsContainer, String fieldName) { - Iterator graphQlFieldDefinitionIterator = - fieldsContainer.getFieldDefinitions().iterator(); - - while (graphQlFieldDefinitionIterator.hasNext()) { - GraphQLFieldDefinition graphQlFieldDefinition = graphQlFieldDefinitionIterator.next(); - + for (GraphQLFieldDefinition graphQlFieldDefinition : fieldsContainer.getFieldDefinitions()) { if (!dataSetNamesWithOutReadPermission.contains(graphQlFieldDefinition.getName()) && graphQlFieldDefinition.getName().equals(fieldName)) { return graphQlFieldDefinition; } - } return null; - - } - - } diff --git a/timbuctoo-instancev4/src/spec/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/LookUpSubjectByUriFetcherWrapperTest.java b/timbuctoo-instancev4/src/spec/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/LookUpSubjectByUriFetcherWrapperTest.java index f9f5a54014..309bb34059 100644 --- a/timbuctoo-instancev4/src/spec/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/LookUpSubjectByUriFetcherWrapperTest.java +++ b/timbuctoo-instancev4/src/spec/java/nl/knaw/huygens/timbuctoo/v5/graphql/datafetchers/LookUpSubjectByUriFetcherWrapperTest.java @@ -1,10 +1,15 @@ package nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers; -import graphql.execution.ExecutionContext; +import graphql.GraphQLContext; +import graphql.cachecontrol.CacheControl; import graphql.execution.ExecutionId; import graphql.execution.ExecutionStepInfo; +import graphql.execution.MergedField; +import graphql.execution.directives.QueryDirectives; +import graphql.language.Document; import graphql.language.Field; import graphql.language.FragmentDefinition; +import graphql.language.OperationDefinition; import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingFieldSelectionSet; import graphql.schema.GraphQLFieldDefinition; @@ -241,11 +246,26 @@ public T getArgument(String name) { return (T) arguments.get(name); } + @Override + public T getArgumentOrDefault(String s, T t) { + throw new IllegalStateException("Not implemented yet"); + } + @Override public T getContext() { throw new IllegalStateException("Not implemented yet"); } + @Override + public GraphQLContext getGraphQlContext() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public T getLocalContext() { + throw new IllegalStateException("Not implemented yet"); + } + @Override public T getRoot() { throw new UnsupportedOperationException("");//FIXME: implement @@ -261,6 +281,11 @@ public List getFields() { throw new IllegalStateException("Not implemented yet"); } + @Override + public MergedField getMergedField() { + throw new IllegalStateException("Not implemented yet"); + } + @Override public Field getField() { throw new UnsupportedOperationException("Not yet implemented");//FIXME: implement @@ -302,13 +327,43 @@ public DataFetchingFieldSelectionSet getSelectionSet() { } @Override - public ExecutionContext getExecutionContext() { - throw new UnsupportedOperationException("Not yet implemented");//FIXME: implement + public QueryDirectives getQueryDirectives() { + throw new IllegalStateException("Not implemented yet"); } @Override public DataLoader getDataLoader(String dataLoaderName) { throw new UnsupportedOperationException("Not yet implemented");//FIXME: implement } + + @Override + public DataLoaderRegistry getDataLoaderRegistry() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public CacheControl getCacheControl() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public Locale getLocale() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public OperationDefinition getOperationDefinition() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public Document getDocument() { + throw new IllegalStateException("Not implemented yet"); + } + + @Override + public Map getVariables() { + throw new IllegalStateException("Not implemented yet"); + } } }