подключите My Spring Boot Graphql к Аполлону - PullRequest
1 голос
/ 25 февраля 2020

Я пытаюсь разработать микросервисы с Spring Boot, которые будут предоставлять GraphQL и подключать их все к Apollo Gateway, но у меня возникает следующая ошибка:

UnhandledPromiseRejectionWarning: Ошибка: Apollo Server требует либо существующую схему, модули или typeDefs

Вот мой код, прикрепленный

Клиент Resolver

@Component
public class ClientResolver implements GraphQLQueryResolver {

    /** The Constant logger. */
    private static final Logger logger = LoggerFactory.getLogger(ClientResolver.class);

    /** The client repository. */
    private ClientRepository clientRepository;

    /**
     * Instantiates a new client resolver.
     *
     * @param clientRepository the client repository
     */
    public ClientResolver(ClientRepository clientRepository) {
        this.clientRepository = clientRepository;
    }

    /**
     * Find a Client by any field.
     *
     * @param client the client
     * @return the iterable
     */
    public Iterable<Client> find(Object client) {

        ObjectMapper mapper = new ObjectMapper();
        Client clientMapped = mapper.convertValue(client, Client.class);

        ExampleMatcher matcher = ExampleMatcher.matching().withIgnoreNullValues().withIgnoreCase();

        Example<Client> exampleClient = Example.of(clientMapped, matcher);

        Iterable<Client> clientFromDb = clientRepository.findAll(exampleClient);

        if (clientFromDb != null) {

            for (Client c : clientFromDb) {
                logger.info("microStrategy getIdClient {}", c.getClientRefId());
            }
        }

        return clientFromDb;
    }
}

Схема клиента

scalar Object

type Client {

 clientRefId : String

 agencyMarketingCampaignExclusionFlag : Boolean

 clientActiveFlag : Boolean
 clientSegmentationMosaicGeocoding : String

 clientSegmentationMosaicGroup : String

 clientSegmentationMosaicIlotCode : String

 clientSegmentationMosaicIlotDetail : String

 clientSegmentationMosaicInseeCode : String

 clientSegmentationMosaicIrisCode : String

 clientSegmentationMosaicLatitude : String

 clientSegmentationMosaicLongitude : String

 clientSegmentationMosaicType : String


 clientSegmentationMosaicWealth : Int

 clientSegmentationMosaicX : String

 clientSegmentationMosaicY : String

 clientSegmentationPotentialStatus : String

 clientSegmentationUrbanCode : String

 clientSeniority : Int

 clientSexCode : String

 clientSirenActive : Boolean

 clientSirenCode : String

 clientSirenInital : String

 clientSiretAssignedAutomaticallyFlag : Boolean

 clientSiretAssignedBySirenFlag : Boolean

 clientSiretCode : String

 clientSiretInital : String

 clientSiretSource : String

 clientSpecificFlag : Boolean

 clientTenantFlag : Boolean

 clientTitle : String

 clientType : String

 clientTypeCode : String

 clientUnsubscribeFlag : Boolean

 clientWealthyFlag : Boolean

 entrepriseName : String
}

type Query {
    find(client : Object): [Client]

}

schema {
  query: Query

}

Шлюз. js


const { ApolloServer } = require('apollo-server');

const { ApolloGateway } = require('@apollo/gateway');

const gateway = new ApolloGateway({
    serviceList: [
      { name: "client", url: "http://localhost:8081/graphql" },

      // { name: "inventory", url: "http://localhost:4004/graphql" }
    ]
  });

  (async () => {
    const { schema, executor } = await gateway.load();

    const server = new ApolloServer({ schema, executor });

    server.listen().then(({ url }) => {
      console.log(` Server ready at ${url}`);
    });
  })();

Сообщение об ошибке

{
  message: "Validation error of type FieldUndefined: Field '_service' in type 'Query' is undefined @ '_service'",
  locations: [ { line: 1, column: 30, sourceName: null } ],
  description: "Field '_service' in type 'Query' is undefined",
  validationErrorType: 'FieldUndefined',
  queryPath: [ '_service' ],
  errorType: 'ValidationError',
  path: null,
  extensions: null
} 0 [
  {
    message: "Validation error of type FieldUndefined: Field '_service' in type 'Query' is undefined @ '_service'",
    locations: [ [Object] ],
    description: "Field '_service' in type 'Query' is undefined",
    validationErrorType: 'FieldUndefined',
    queryPath: [ '_service' ],
    errorType: 'ValidationError',
    path: null,
    extensions: null
  }
]
[INFO] Tue Feb 25 2020 15:25:52 GMT+0100 (GMT+01:00) apollo-gateway: Gateway successfully loaded schema.
        * Mode: unmanaged
(node:70412) UnhandledPromiseRejectionWarning: Error: Apollo Server requires either an existing schema, modules or typeDefs
    at ApolloServer.initSchema (c:\NWLS\workspace-ASK\federation-demo-master\node_modules\apollo-server-core\dist\ApolloServer.js:240:23)

в Java Консоль У меня есть это сообщение

Query failed to validate : 'query GetServiceDefinition { _service { sdl } }'

Есть мысли?

...