ℹ️ This project is a proof of concept
GraphQL integration for ksqlDB to facilitate easier app creation by abstracting ksqlDB syntax and protocol.
KLIP-15 creates a new API with which to interact. This repository contains packages to generate graphQL as well as handle the ksqlDB protocol.
yarn add @confluentinc/ksqldb-graphql
For statements to be executed against ksqDB, RequestOptions must be provided, both at startup and in the context of the graphQL resolvers.
The prebuild step, generateGraphQL
, returns a promise and should be called prior to starting a graphQL server.
import { connect } from 'http2';
import { ApolloServer } from 'apollo-server';
import { generateGraphQL } from '@confluentinc/ksqldb-graphql';
import { addResolveFunctionsToSchema } from 'graphql-tools';
const session = connect(`http://localhost:8088`);
const options = {
hostname: 'localhost',
port: 8088,
};
generateGraphQL({ options }).then(
({ schemas, queryResolvers, subscriptionResolvers, mutationResolvers }) => {
const server = new ApolloServer({
context: async () => ({
ksqlDB: {
options,
session,
},
}),
schema: addResolveFunctionsToSchema({
schema: schemas,
resolvers: {
Subscription: subscriptionResolvers,
Query: queryResolvers,
Mutation: mutationResolvers,
}
}),
subscriptions: {
keepAlive: 1000,
},
});
server.listen();
}
);
Generates the schema and resolvers based on an existing ksqlDB cluster.
Resolves the ksqlDB protocol and executes ksqlDB statements