@Override public GraphQLType getParentType() { return delegate.getParentType(); }
public DataFetcher<String> typeFetcher(Map<String, TypeConfig> types) { return environment -> { String typeName = environment.getParentType().getName(); return (types.containsKey(typeName)) ? types.get(typeName).getId() : null; }; }
public DataFetcher<String> typeFetcher(Map<String, TypeConfig> types) { return environment -> { String typeName = environment.getParentType().getName(); return (types.containsKey(typeName)) ? types.get(typeName).getId() : null; }; }
@Override public TypedValue get(DataFetchingEnvironment env) { if (env.getSource() instanceof SubjectReference) { SubjectReference source = env.getSource(); DataSet dataSet = source.getDataSet(); if (env.getParentType() instanceof GraphQLObjectType) { String type = getDirectiveArgument((GraphQLObjectType) env.getParentType(), "rdfType", "uri").orElse(null); Optional<TypedValue> summaryProperty = summaryPropDataRetriever.createSummaryProperty(source, dataSet, type); if (summaryProperty.isPresent()) { return summaryProperty.get(); } } } return null; }
@Override public TypedValue get(DataFetchingEnvironment env) { if (env.getSource() instanceof SubjectReference) { SubjectReference source = env.getSource(); DataSet dataSet = source.getDataSet(); if (env.getParentType() instanceof GraphQLObjectType) { String type = getDirectiveArgument((GraphQLObjectType) env.getParentType(), "rdfType", "uri").orElse(null); Optional<TypedValue> summaryProperty = summaryPropDataRetriever.createSummaryProperty(source, dataSet, type); if (summaryProperty.isPresent()) { return summaryProperty.get(); } } } return null; } }
@Override public Object convertOutput(Publisher<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //Subscriptions are expected to return a Publisher directly, so no conversion needed if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //Otherwise, convert the Publisher into a CompletableFuture return convertOutputForNonSubscription(original, type, resolutionEnvironment); }
@Override public Object convertOutput(Mono<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //For subscriptions, Mono<T> (Publisher<T>) should be returned directly if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //For other operations it must be converted into a CompletableFuture<T> return original.toFuture(); }
@Override public TypedValue get(DataFetchingEnvironment env) { if (env.getSource() instanceof SubjectReference) { SubjectReference source = env.getSource(); DataSet dataSet = source.getDataSet(); if (env.getParentType() instanceof GraphQLObjectType) { String type = getDirectiveArgument((GraphQLObjectType) env.getParentType(), "rdfType", "uri").orElse(null); Optional<TypedValue> summaryProperty = summaryPropDataRetriever.createSummaryProperty(source, dataSet, type); if (summaryProperty.isPresent()) { return summaryProperty.get(); } } // fallback to the uri if no summary props can be found for the title return TypedValue.create(source.getSubjectUri(), STRING, dataSet); } return null; }
@Override public Object convertOutput(Mono<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //For subscriptions, Mono<T> (Publisher<T>) should be returned directly if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //For other operations it must be converted into a CompletableFuture<T> return original.toFuture(); }
public FetchParams(DataFetchingEnvironment environment, HGQLSchema hgqlschema) { subjectResource = environment.getSource(); String predicate = ((Field) environment.getFields().toArray()[0]).getName(); predicateURI = hgqlschema.getFields().get(predicate).getId(); client = environment.getContext(); if (!environment.getParentType().getName().equals("Query")) { String targetName = hgqlschema.getTypes().get(environment.getParentType().getName()).getField(predicate).getTargetName(); if (hgqlschema.getTypes().containsKey(targetName) && hgqlschema.getTypes().get(targetName).getId()!=null) { targetURI=hgqlschema.getTypes().get(targetName).getId(); } } }
public FetchParams(DataFetchingEnvironment environment, HGQLSchema hgqlschema) { subjectResource = environment.getSource(); String predicate = ((Field) environment.getFields().toArray()[0]).getName(); predicateURI = hgqlschema.getFields().get(predicate).getId(); client = environment.getContext(); if (!environment.getParentType().getName().equals("Query")) { String targetName = hgqlschema.getTypes().get(environment.getParentType().getName()).getField(predicate).getTargetName(); if (hgqlschema.getTypes().containsKey(targetName) && hgqlschema.getTypes().get(targetName).getId()!=null) { targetURI=hgqlschema.getTypes().get(targetName).getId(); } } }
public ResolutionEnvironment(DataFetchingEnvironment env, ValueMapper valueMapper, GlobalEnvironment globalEnvironment, ConverterRegistry converterRegistry) { this.context = env.getSource(); this.rootContext = env.getContext(); this.valueMapper = valueMapper; this.globalEnvironment = globalEnvironment; this.converterRegistry = converterRegistry; this.fields = env.getFields(); this.fieldType = env.getFieldType(); this.parentType = env.getParentType(); this.graphQLSchema = env.getGraphQLSchema(); this.dataFetchingEnvironment = env; this.arguments = new HashMap<>(); }
@Test @DisplayName("Environment parent type must have a name") void environment_must_have_parent_type_name() { HGQLSchema schema = mock(HGQLSchema.class); DataFetchingEnvironment environment = mock(DataFetchingEnvironment.class); Field field1 = mock(Field.class); List<Field> fields = Collections.singletonList(field1); when(environment.getFields()).thenReturn(fields); when(field1.getName()).thenReturn("field1"); FieldConfig fieldConfig = mock(FieldConfig.class); Map<String, FieldConfig> schemaFields = Collections.singletonMap("field1", fieldConfig); when(schema.getFields()).thenReturn(schemaFields); GraphQLType parentType = mock(GraphQLType.class); when(environment.getParentType()).thenReturn(parentType); Executable executable = () -> new FetchParams(environment, schema); assertThrows(NullPointerException.class, executable); }
public Object getUnbatched(DataFetchingEnvironment env) { if ( ! isBatched ) return fetcher.get(env); DataFetchingEnvironment envCopy = new DataFetchingEnvironmentImpl( Collections.singletonList(env.getSource()), env.getArguments(), env.getContext(), env.getFields(), env.getFieldType(), env.getParentType(), env.getGraphQLSchema(), env.getFragmentsByName(), env.getExecutionId(), env.getSelectionSet()); Object result = fetcher.get(envCopy); if ( !(result instanceof List) || ((List)result).size() != 1 ) { throw new IllegalStateException("Batched fetcher "+fetcher+" expected to return list of 1"); } return ((List)result).get(0); }
@Override public Object get(DataFetchingEnvironment env) { Object source = ( null != impl ) ? impl : env.getSource(); if (source == null) return null; if (source instanceof ResolveDataFetchingEnvironment) { source = ((ResolveDataFetchingEnvironment)source).resolve(env); } return getMethodViaGetter(source, env.getFieldType(), getFieldType(env.getParentType()), env.getArguments()); }
@Override public Object get(DataFetchingEnvironment env) { Object source = ( null != impl ) ? impl : env.getSource(); if (source == null) return null; if (source instanceof ResolveDataFetchingEnvironment) { source = ((ResolveDataFetchingEnvironment)source).resolve(env); } return getMethodViaGetter(source, env.getFieldType(), getFieldType(env.getParentType()), env.getArguments()); }
@Override public Object get(DataFetchingEnvironment environment) { // Exclude arguments DataFetchingEnvironment env = new DataFetchingEnvironmentImpl(environment.getSource(), new HashMap<>(), environment.getContext(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet()); Connection conn = constructNewInstance(constructor, actualDataFetcher.get(env)); return conn.get(environment); } }
@Override public T get(DataFetchingEnvironment environment) throws Exception { Object source = environment.getSource(); if (source != null && (!declaringClass.isInstance(source)) && !(source instanceof Map)) { environment = new DataFetchingEnvironmentImpl(newInstance(declaringClass, source), environment.getArguments(), environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext()); } return dataFetcher.get(environment); }
public WherePredicateEnvironment(DataFetchingEnvironment environment, GraphQLFieldDefinition fieldDefinition, Map<String, Object> arguments) { super( environment.getSource(), arguments, environment.getContext(), environment.getRoot(), fieldDefinition, //environment.getFieldDefinition(), environment.getFields(), fieldDefinition.getType(), // environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ); } }
public ArgumentEnvironment(DataFetchingEnvironment environment, String argumentName) { super( environment.getSource(), environment.getArgument(argumentName), environment.getContext(), environment.getRoot(), environment.getFieldDefinition(), environment.getFields(), environment.getFieldType(), environment.getParentType(), environment.getGraphQLSchema(), environment.getFragmentsByName(), environment.getExecutionId(), environment.getSelectionSet(), environment.getExecutionStepInfo(), environment.getExecutionContext() ); } }