Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/graphql/schema/DataFetchingEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import graphql.language.OperationDefinition;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -28,6 +28,7 @@
*/
@SuppressWarnings("TypeParameterUnusedInFormals")
@PublicApi
@NullMarked
public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnvironment {

/**
Expand Down Expand Up @@ -92,6 +93,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
* @deprecated - use {@link #getGraphQlContext()} instead
*/
@Deprecated(since = "2021-07-05")
@Nullable
<T> T getContext();

/**
Expand All @@ -102,7 +104,6 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return can NOT be null
*/
@NonNull
GraphQLContext getGraphQlContext();

/**
Expand Down Expand Up @@ -130,6 +131,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return can be null
*/
@Nullable
<T> T getRoot();

/**
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/graphql/schema/DataFetchingEnvironmentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import graphql.language.OperationDefinition;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand All @@ -31,6 +31,7 @@

@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
@Internal
@NullMarked
public class DataFetchingEnvironmentImpl implements DataFetchingEnvironment {
private final Object source;
private final Supplier<Map<String, Object>> arguments;
Expand Down Expand Up @@ -112,6 +113,7 @@ public static Builder newDataFetchingEnvironment(ExecutionContext executionConte
}

@Override
@Nullable
public <T> T getSource() {
return (T) source;
}
Expand All @@ -127,7 +129,7 @@ public boolean containsArgument(String name) {
}

@Override
public <T> T getArgument(String name) {
public @Nullable <T> T getArgument(String name) {
return (T) arguments.get().get(name);
}

Expand All @@ -137,12 +139,12 @@ public <T> T getArgumentOrDefault(String name, T defaultValue) {
}

@Override
public <T> T getContext() {
public @Nullable <T> T getContext() {
return (T) context;
}

@Override
public @NonNull GraphQLContext getGraphQlContext() {
public GraphQLContext getGraphQlContext() {
return graphQLContext;
}

Expand All @@ -152,7 +154,7 @@ public <T> T getContext() {
}

@Override
public <T> T getRoot() {
public @Nullable <T> T getRoot() {
return (T) root;
}

Expand Down Expand Up @@ -333,13 +335,13 @@ public Builder arguments(Supplier<Map<String, Object>> arguments) {
}

@Deprecated(since = "2021-07-05")
public Builder context(Object context) {
public Builder context(@Nullable Object context) {
this.context = context;
return this;
}

public Builder graphQLContext(GraphQLContext context) {
this.graphQLContext = context;
this.graphQLContext = Assert.assertNotNull(context, "GraphQLContext cannot be null");
return this;
}

Expand Down