GraphQL CRUD Java: Overview

GraphQL CRUD Java: Overview:

 

What is GraphQL CRUD Java?

GraphQLCRUD java is an extensive framework built using the GraphQLCRUD spec which provides a specification for common operation on top of GraphQL. It provides numerous options for users to access and modify their data from any data sources they are connected to.

Common Features

  • Check specifications for patterns and pick only those that will really work for your specific database or business requirements.
  • It provides canonical versions and other variants giving you an overview of different approaches used in most schemas.
  • Focus on your business logic and data and generate GraphQL CRUD compliant schemas in any language of your choice.
  • It abstracts from large GraphQL vendors giving you flexibility, and the ability to migrate without rebuilding your clients and resolves.
  • It focuses on productivity by giving developers powerful query capabilities that are not specific to any GraphQL solution providers.

CRUD methods

GraphQL CRUD java defines different CRUD capabilities that represent various operations that can be executed on a set of objects:

  • Create: create an object
  • Update: update a specific object’s properties
  • Delete: delete a specific object by its ID
  • Get: get a specific object by its ID
  • Find: find multiple objects

Capabilities

GraphQL CRUD java defines different capabilities that developers can enable to modify what queries can be made against the service. Examples of these capabilities include:

  • Pagination: Ability to paginate content
  • Filtering: Ability to perform filtering on specific fields
  • Countability: Ability to count the total number of objects
  • Consistency: Ability to verify whether a write operation is overriding data

How it works?

Take any database, the GraphQL CRUD java engine can automatically generate a GraphQL schema and process GraphQL queries and mutations. Here’s what the engine does under the hood.

  • The GraphQL CRUD java engine automatically generates GraphQL schema components and creates relationships between them.
  • It defines a GraphQL type definition for your database.
  • Provides Query with filter,order_by, and page arguments.
  • Provides Insert mutations with the input argument that supports insert operation.
  • Provides Update mutation with filter and input argument that supports bulk updates.
  • Provides Delete mutation with a filter argument that supports bulk deletes.
Example: Fetch list of all accounts
#Input
{
  accounts {
    account_id
    status
    ssn
    }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "accounts": [
      {
        "account_id": "19980001",
        "status": "Personal",
        "ssn": "CST01002"
      },
      {
        "account_id": "19980002",
        "status": "Personal",
        "ssn": "CST01002"
      },
      {
        "account_id": "19980003",
        "status": "Personal",
        "ssn": "CST01003"
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode
Example: Fetch an account using the primary key
#Input
{
  account(account_id: 19980001) {
    account_id
    ssn
    status
    type
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "account": {
      "account_id": "19980001",
      "ssn": "CST01002",
      "status": "Personal",
      "type": "Active"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
Example: Fetch a customer whose name is James
#Input
{
  customers(filter: {
    firstname: {
      eq: "James"
    }
  }) {
    firstname
    lastname
    ssn
    phone
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "customers": [
      {
        "firstname": "James",
        "lastname": "Drew",
        "ssn": "CST01036",
        "phone": "(216)555-6523"
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode
Example: Fetch 2 customers from the list of all customers, starting from first
#Input
{
  customers(page: {
    limit: 2
  }) {
    firstname
    lastname
    ssn
    phone
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "customers": [
      {
        "firstname": "John",
        "lastname": "Doe",
        "ssn": "CST01002  ",
        "phone": "(646)555-1776"
      },
      {
        "firstname": "Bob",
        "lastname": "Smith",
        "ssn": "CST01003  ",
        "phone": "(412)555-4327"
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode
Example: Fetch 2 customers from the list of all customers, starting from the 2nd customer
#Input
{
  customers(filter: {
    firstname: {
      startsWith: "J"
    }
  }, page: {
    limit: 2,
    offset: 2
  }) {
    firstname
    lastname
    ssn
    phone
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "customers": [
      {
        "firstname": "Jack",
        "lastname": "Corby",
        "ssn": "CST01015  ",
        "phone": "(469)555-8023"
      },
      {
        "firstname": "James",
        "lastname": "Drew",
        "ssn": "CST01036  ",
        "phone": "(216)555-6523"
      }
    ]
  }
}

Enter fullscreen mode Exit fullscreen mode
Example: Insert a new customer object and return the inserted customer object in the response
#Input
mutation {
  createCustomer(input: {
    firstname: "James",
    lastname: "Corners",
    ssn: "CST00989"
  }) {
    firstname
    lastname
    ssn
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "createCustomer": {
      "firstname": "James",
      "lastname": "Corners",
      "ssn": "CST00989"
    }
  }
} 
Enter fullscreen mode Exit fullscreen mode
Example: Update a customer with the name Bob and return the updated customer object in the response
#Input
mutation {
  updateCustomer (input: {
    firstname: "Andrew",
    lastname: "Moore"
  }, filter: {
    firstname: {
      eq: "Bob"
    }
  }) {
    firstname
    lastname
    ssn
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "updateCustomer": {
      "firstname": "Andrew",
      "lastname": "Moore",
      "ssn": "CST01003"
    }
  }
} 
Enter fullscreen mode Exit fullscreen mode
Example: Delete a customer where name is Andrew
#Input
mutation {
  deleteCustomer(filter: {
    firstname: {
      eq: "Andrew"
    }
  }) {
    firstname
    lastname
    ssn
    phone
  }
}
Enter fullscreen mode Exit fullscreen mode
#Output
{
  "data": {
    "deleteCustomer": {
      "firstname": "Andrew",
      "lastname": "Moore",
      "ssn": "CST01003"
    }
  }
} 

Enter fullscreen mode Exit fullscreen mode

You can explore the entire schema and the available queries using the GraphiQL interface. You can expand the framework as per your needs to make it more robust.

from Tumblr https://generouspiratequeen.tumblr.com/post/634113095682375680

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s