Я просматривал ваш коммит для # 190 Удивительные мысли для Федерации.
Если возможно, не могли бы вы поделиться примером кода для реализации федерации из Graphql-compose-elasti c?
Кроме того, к вашему сведению, вам может потребоваться изменить некоторые значения "des c" для типа данных DateType в файлах elasti c. Это нарушает федерацию Apollo для чтения схемы.
Вот как я пытался реализовать, но не получилось.
Проблема в том, что объединение _entities не регистрируется в схеме.
Код репо: https://github.com/amarflybot/graphql-compose-apollo-federation
import * as express from 'express';
import {default as expressPlayground} from "graphql-playground-middleware-express";
import {express as voyagerMiddleware} from "graphql-voyager/middleware";
import {altairExpress} from "altair-express-middleware";
import {graphql, ObjectTypeComposer, printSchema, schemaComposer} from "graphql-compose";
import {composeWithElastic} from "graphql-compose-elasticsearch";
import * as elasticsearch from "elasticsearch";
import {ApolloServer, gql} from "apollo-server-express";
import {buildFederatedSchema} from "./buildFederatedSchema";
const { GraphQLSchema, GraphQLObjectType } = graphql;
const expressPort = process.env.port || process.env.PORT || 9201;
const ecommerceMapping = {
"properties" : {
// Mappings
};
let elasticClient = new elasticsearch.Client({
host: 'http://elastic:changeme@localhost:9200',
apiVersion: '7.5',
log: 'trace'
});
const EcommerceEsTC = composeWithElastic({
graphqlTypeName: 'ecommerce',
elasticIndex: 'kibana_sample_data_ecommerce',
elasticType: '_doc',
elasticMapping: ecommerceMapping,
elasticClient: elasticClient
});
const ProxyTC = ObjectTypeComposer.createTemp(`type ProxyDebugType { source: JSON }`);
ProxyTC.addResolver({
name: 'showArgs',
kind: 'query',
args: {
source: 'JSON',
},
type: 'ProxyDebugType',
resolve: ({ args }) => args,
});
EcommerceEsTC.addRelation('showRelationArguments', {
resolver: () => ProxyTC.getResolver('showArgs'),
prepareArgs: {
source: source => source,
}
});
let ContentTC = schemaComposer.createObjectTC(`
extend type Content @key(fields: "id") {
id: String! @external
ecommerces: [ecommerceecommerce]
}
`);
let typesFieldsResolve = {
'Content': {
'ecommerces':(source, args, context, info) => {
console.log("Here I am");
return null;
}
}
};
schemaComposer.addResolveMethods(typesFieldsResolve);
const generatedSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
ecommerceSearch: EcommerceEsTC.getResolver('search').getFieldConfig(),
ecommercePagination: EcommerceEsTC.getResolver('searchPagination').getFieldConfig(),
ecommerceSearchConnection: EcommerceEsTC.getResolver('searchConnection').wrapResolve(next => async (rp) => {
const { source, args, context, info } = rp;
// check here args or contexts, or even you can change `rp.args` before passing it down to `search` resolver
const result = await next(rp);
// check and change result here before returning it to user
console.log(result);
return result;
}).getFieldConfig()
},
}),
});
schemaComposer.getOTC('ecommerceSearchHitItem')
.removeField(['_index','_score','_shard','_node','_explanation','_version','_type'])
.clearExtensions();
const app = express();
const server = new ApolloServer({
schema: buildFederatedSchema(generatedSchema)
});
server.applyMiddleware({ app });
app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' }));
app.use('/playground', expressPlayground({ endpoint: '/graphql' }));
app.use('/altair', altairExpress({endpointURL: '/graphql'}));
app.listen(expressPort, () => {
console.log(`The server is running at http://localhost:${expressPort}/`);
});