-
Notifications
You must be signed in to change notification settings - Fork 4
Adding Graphql CRUD functionality
Spring and java-graphql implicitly wire up compatible graphql resolvers and schema.
The following pull request shows an example of how to create and "wire" basic CRUD for a new graphql entity that is stored in a database: KafkaConnect: https://github.com/codingblocks/grafka/pull/27/files
schema.graphqls contains the graphql schema that defines what functionality is available to the client.
The definition for the "KafkaConnect" entity maps to the KafkaConnect.kt file in Kotlin. It is currently a stand-alone object, so we need to a new Query definition to let clients query.
The definitions in the Query and Mutation types map to the KafkaConnectResolver. The function names and arguments are wired implicitly, so they must exactly match the definition in schema.graphqls. There is probably some way to explicitly associate via annotations too. Note that KafkaConnectResolver implements GraphQLQueryResolver and GraphQLMutationResolver, it doesn't implement any behavior but these implementations are required for the wiring.
The persistence layer is standard Spring fare, utilizing the annotations in the KafkaConnectConfig.kt class. Tables are automatically created by default, as configured in the application properties.
Create a new Connect object, and return the new object with it's generated id:
mutation {
newConnect(name: "Test Name", config: "Test Config") {
connectId
name
config
}
}
Get all Connect objects, this method should probably be named "connects"...but it's not:
{
connect {
connectId
name
config
}
}
You can filter by id as well:
{
connect(connectId: "your-id-here") {
name
}
}
Update a connect instance:
mutation {
updateConnect(connectId:"your-id-here", name: "Test Name", config: "Test Config") {
connectId
name
config
}
}
Finally, you can delete a connect instance:
mutation {
deleteConnect(connectId:"your-id-here")
}
TODO: Add link to wiki showing how to relate entities...once it's written!
Connect is a framework built-on top of Kafka that provides basic input and output functionality. This pull request adds support for adding the necessary configurations for (eventual) integration.
There are numerous available configurations, so the plan is just to passthrough any text that the user passes to the environment.
Read more about the Kafka architecture as it relates to grafka in the wiki: https://github.com/codingblocks/grafka/wiki/Terminology