Giter Club home page Giter Club logo

springbootgraphql's Introduction

  1. GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.
  2. GraphQL provides a complete and understandable description of the data in your API.
  3. It gives clients the power to ask for exactly what they need and nothing more.

Screenshot from 2022-06-07 10-47-17 When you are using graphQL in SpringBoot you need to write schema file with extension .graphqls and put under src/main/resources/graphql folder

Screenshot from 2022-06-07 11-04-33

For accessing Graphiql ui you need to add one property in applicaion.(properties OR yml) i.e spring.graphql.graphiql.enabled=true Screenshot from 2022-06-07 11-12-23

Screenshot from 2022-06-07 11-12-38

  1. To work with GraphQL first need to understand scalar-types

  2. GraphQL comes with a set of default scalar types out of the box:

    (i) Int: A signed 32‐bit integer. (ii) Float: A signed double-precision floating-point value. (iii) String: A UTF‐8 character sequence. (iv) Boolean: true or false. (v) ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache.

  3. By using these scalar types we can write Query's and Mutation's.

    Defining type:

       type Address{
              addressId:ID!
              streetName:String!
              pinNumber:Int!
              city:String!
        }
        type Customer{
              customerId:ID!
              customerName:String!
              customerPhoneNumber:String!
              customerAddress:[Address]!
              customerSignUpDate:String!
              customerAccountVerified:Boolean
        }
    
  4. Writing Query's:- Query is similar (GET HTTP Method)

    Query Example:-

     type Query{
         getCustomerById(customerId:Int!):Customer
         getCustomers:[Customer]
     }
    
  5. Writing mutations:- Mutations are similar to (POST,PUT,DELETE HTTP methods)

    Mutation Exmaple:-

    input updateCustomerInput{
             customerId:ID!
             customerName:String!
             customerPhoneNumber:String!
             customerAddress:[addressInput]!
             customerSignUpDate:String!
             customerAccountVerified:Boolean
     }
    input addressInput{
             addressId:ID
             streetName:String!
             pinNumber:Int!
             city:String!
     }
    type Mutation{
         saveAddress(address:addressInput) : Address
         saveCustomer(customer:customerInput) : Customer
         deleteCustomer(customerId:Int!):String
         updateCustomer(customer:updateCustomerInput):Customer
    }
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.