Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullability annotations in DataFetchingEnvironment & sub-classes #3582

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
7 changes: 7 additions & 0 deletions src/main/java/graphql/schema/DataFetchingEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import graphql.language.OperationDefinition;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Locale;
Expand All @@ -37,6 +39,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return can be null for the root query, otherwise it is never null
*/
@Nullable
<T> T getSource();

/**
Expand All @@ -61,6 +64,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return the named argument or null if it's not present
*/
@Nullable
<T> T getArgument(String name);

/**
Expand Down Expand Up @@ -97,6 +101,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return can NOT be null
*/
@NotNull
GraphQLContext getGraphQlContext();

/**
Expand All @@ -114,6 +119,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @return can be null if no field context objects are passed back by previous parent fields
*/
@Nullable
<T> T getLocalContext();

/**
Expand Down Expand Up @@ -228,6 +234,7 @@ public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnviro
*
* @see org.dataloader.DataLoaderRegistry#getDataLoader(String)
*/
@Nullable
<K, V> DataLoader<K, V> getDataLoader(String dataLoaderName);

/**
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/graphql/schema/DataFetchingEnvironmentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import graphql.language.OperationDefinition;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -129,12 +131,12 @@ public <T> T getContext() {
}

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

@Override
public <T> T getLocalContext() {
public <T> @Nullable T getLocalContext() {
return (T) localContext;
}

Expand Down Expand Up @@ -204,7 +206,7 @@ public ExecutionStepInfo getExecutionStepInfo() {
}

@Override
public <K, V> DataLoader<K, V> getDataLoader(String dataLoaderName) {
public <K, V> @Nullable DataLoader<K, V> getDataLoader(String dataLoaderName) {
return dataLoaderRegistry.getDataLoader(dataLoaderName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import graphql.language.OperationDefinition;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -70,12 +72,12 @@ public <T> T getContext() {
}

@Override
public GraphQLContext getGraphQlContext() {
public @NotNull GraphQLContext getGraphQlContext() {
return delegateEnvironment.getGraphQlContext();
}

@Override
public <T> T getLocalContext() {
public <T> @Nullable T getLocalContext() {
return delegateEnvironment.getLocalContext();
}

Expand Down Expand Up @@ -146,7 +148,7 @@ public QueryDirectives getQueryDirectives() {
}

@Override
public <K, V> DataLoader<K, V> getDataLoader(String dataLoaderName) {
public <K, V> @Nullable DataLoader<K, V> getDataLoader(String dataLoaderName) {
return delegateEnvironment.getDataLoader(dataLoaderName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql.schema

import graphql.GraphQLContext
import org.jetbrains.annotations.NotNull
import spock.lang.Specification

class DelegatingDataFetchingEnvironmentTest extends Specification {
Expand All @@ -22,6 +23,7 @@ class DelegatingDataFetchingEnvironmentTest extends Specification {

when:
def delegatingDFE = new DelegatingDataFetchingEnvironment(dfe) {
@NotNull
@Override
GraphQLContext getGraphQlContext() {
return GraphQLContext.of(["key": "overriddenContext"])
Expand Down
Loading