Skip to content

YummyCookhouse/springboot-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is this?

This is an example to show how to get graphql works with springboot

Dependencies

Reference

Features

Already have

  • Query list
  • Query with arguments
  • Mutation
  • Union type
  • Field resolver
  • Mutation with input type
  • Fragment
  • Nested query

To be added

  • Defer

How to play

  1. Download graphiql app

  2. ./gradlew bootrun

  3. Visit http://localhost:8081/graphql in GraphiQL

    Query all pets
    query {
         pets {
            ...on Bird {
              name
              type
              wings
              owner {
                name
              }
            }
          	...on Dog {
              name
              type
              license
              owner {
                name,
                address
              }
            }
        }
    }
    
    Query pet with specific id
    query {
      pet(id: 1) {
        ...on Bird {
              name
              type
              wings
              owner {
                name
              }
            }
        ...on Dog {
              name
              type
              license
              owner {
                name,
                address
              }
        }
      }
    }
    
    Update/create a dog
     mutation {
     	saveDog(id:-1, name: "XXX", age: 12, ownerId: 2, license: "dssd") {
             name
             type
        }
     }
    
    Create a pet with input type
    mutation {
      addPet(pet: {
        id: 99
        ownerId: 1
        name: "Mooo"
        type: DOG
        age: 10
        license: "555555"
      }) {
        ...on Dog {
          name
          type
        }
      }
    }
    
    Play with fragment
    query{
      pets {
        ...AllKindsOfPet
      }
    }
    
    fragment AllKindsOfPet on Pet {
      ...on Dog {
          type
        	name
        	owner {
            name
          }
      }
      ...on Bird {
        	type
          name
        	owner {
            name
          }
      }
    }
    
    Play with nested query
    query {
      pets {
        ...on Bird {
          name
          owner {
            identifier(type: PASSPORT)
          }
        }
      }
    }  
    

    Troubleshooting

    Q: Docs doesn't work in GraphiQL

    A: Click Edit HTTP Headers on right-top and add header Authorization

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages