apollographql / federation-jvm

JVM support for Apollo Federation

Home Page:https://www.apollographql.com/docs/federation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using graphql-java-tools does not expose an entity or SDL

reduxdj opened this issue · comments




import com.apollographql.federation.graphqljava.SchemaTransformer;
import com.apollographql.federation.graphqljava._Entity;
import com.apollographql.federation.graphqljava.caching.CacheControlInstrumentation;
import com.apollographql.federation.graphqljava.tracing.FederatedTracingInstrumentation;
import com.chainalysis.social.messaging.Message;
import graphql.schema.GraphQLSchema;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("graphql-java-tools")
public class AppConfiguration {
    @Bean
    public GraphQLSchema graphQLSchema(SchemaTransformer schemaTransformer) {
        return schemaTransformer
                .fetchEntities(
                        env ->
                                env.<List<Map<String, Object>>>getArgument(_Entity.argumentName).stream()
                                        .map(
                                                reference -> {
                                                    if ("Message".equals(reference.get("__typename"))) {
                                                        return MessageReferenceResolver.resolveReference(reference);
                                                    }
                                                    return null;
                                                })
                                        .collect(Collectors.toList()))
                .resolveEntityType(
                        env -> {
                            final Object src = env.getObject();
                            if (src instanceof Message) {
                                return env.getSchema().getObjectType("Message");
                            }
                            return null;
                        })
                .build();
    }

    @Bean
    public FederatedTracingInstrumentation federatedTracingInstrumentation() {
        return new FederatedTracingInstrumentation(new FederatedTracingInstrumentation.Options(true));
    }

    @Bean
    public CacheControlInstrumentation cacheControlInstrumentation() {
        return new CacheControlInstrumentation();
    }
}

query Query {
_service {
sdl
}
}


```{
  "errors": [
    {
      "message": "Validation error of type FieldUndefined: Field '_service' in type 'Query' is undefined @ '_service'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "classification": "ValidationError"
      }
    }
  ],
  "data": null
}```

@reduxdj What was the fix for this?

Hello 👋
@berdon Unsure what was the original issue but if you are hitting the same problem, can you create a new issue with a link to a repo that reproduces the issue?