Giter Site home page Giter Site logo

spring-boot-graphql-query-example's Introduction

Spring Boot with GraphQL Query Example

Update: Upgraded to Java 11 and Graph QL to 5+ version dependency

Book Store

  • /rest/books is the REST resource which can fetch Books information
  • DataFetchers are Interfaces for RuntimeWiring of GraphQL with JpaRepository

Sample GraphQL Scalar Queries

  • Accessible under http://localhost:8091/rest/books
  • Usage for allBooks
{
   allBooks {
     isn
     title
     authors
     publisher
   }
 }
  • Usage for book
  {
   book(id: "123") {
     title
     authors
     publisher
   }
  • Combination of both allBooks and book
{
   allBooks {
     title
     authors
   }
   book(id: "124") {
     title
     authors
     publisher
   }
 }

spring-boot-graphql-query-example's People

Contributors

movingtoweb avatar shah-smit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-boot-graphql-query-example's Issues

GraphiQL

How can I use GraphiQL to query?
I can query using Postman, but GraphiQL show and error:

{
  "errors": [
    {
      "message": "Invalid Syntax",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ],
      "errorType": "InvalidSyntax"
    }
  ],
  "data": null,
  "extensions": null
}

And in the app console I can see the following error:
graphql.GraphQL : Executing request. operation name: null. Request: {"query":"{\n\n\n\tbook (id: \"111\"){\n\t\tisn\n\t\ttitle\n\t\tauthors\n\t}\n\n\n}","variables":null,"operationName":null}

It seems that GraphiQL add "query" at the top of the request.

InvalidSyntax error on executing this project

While trying to execute the project using below query

{
book(id: "123") {
title
authors
publisher
}
}

I am getting below error.

{
"data": null,
"errors": [
{
"message": "Invalid Syntax",
"locations": [
{
"line": 1,
"column": 1,
"sourceName": null
}
],
"errorType": "InvalidSyntax",
"path": null,
"extensions": null
}
],
"dataPresent": false,
"extensions": null
}

On server side I am getting below error

2021-05-12 18:11:10.346 WARN 16964 --- [o-auto-1-exec-5] graphql.GraphQL : Query failed to parse : '{"operationName":null,"variables":{},"query":"{\n book(id: "123") {\n title\n authors\n publisher\n }\n}\n"}'

Please help in understanding the root cause of this problem and how to fix the same.

GraphQL doesn't work

Hi,
I'm new to Spring boot framework and graphql.
I have tried this project myself. But it doesn't work. I got errors like this,

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-02-07 22:07:04.571 ERROR 5265 --- [ main] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration': Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect bean class [com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$c0109e00] for persistence metadata: could not find class that it depends on
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at com.techprimers.graphql.springbootgrapqlexample.SpringBootGrapqlExampleApplication.main(SpringBootGrapqlExampleApplication.java:10) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect bean class [com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$c0109e00] for persistence metadata: could not find class that it depends on
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:401) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:333) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:992) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 15 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Lcom/coxautodev/graphql/tools/SchemaParserOptions;
at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_101]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[na:1.8.0_101]
at java.lang.Class.getDeclaredFields(Class.java:1916) ~[na:1.8.0_101]
at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:715) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:656) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:418) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:397) ~[spring-orm-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.coxautodev.graphql.tools.SchemaParserOptions
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_101]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_101]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_101]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_101]
... 25 common frames omitted

Process finished with exit code 1

Can anyone help me to solve this problem???

how to pass List data type to the graphql

I watch the video on youtube and I have a question of pass special data type. for example, if there are two entities class inside the model, one is for Book like yours and another one is author. In the Book entity class, private List <author> authors. And in the author class, it contains: authorName, authorAge.... In this case, how should pass authors list into the graphql script?

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.