├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ └── DemoGraphQL │ │ ├── DemoGraphQlApplication.java │ │ ├── MyProperties.java │ │ ├── exception │ │ ├── BookNotFoundException.java │ │ └── GraphQLErrorAdapter.java │ │ ├── model │ │ ├── Author.java │ │ └── Book.java │ │ ├── repository │ │ ├── AuthorRepository.java │ │ └── BookRepository.java │ │ └── resolver │ │ ├── BookResolver.java │ │ ├── Mutation.java │ │ └── Query.java └── resources │ ├── application.yml │ └── graphql │ ├── author.graphqls │ └── book.graphqls └── test └── java └── com └── example └── DemoGraphQL ├── DemoGraphQlApplicationTests.java └── resolver └── QueryTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eh3rrera/graphql-java-spring-boot-example/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Esteban Herrera 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graphql-java-spring-boot-example 2 | Sample app for my tutorial [Building a GraphQL Server with Spring Boot](https://app.pluralsight.com/guides/building-a-graphql-server-with-spring-boot). 3 | 4 | Updated by [@Ansonator](https://github.com/Ansonator) to recent versions of Spring Boot and GraphQL Java. 5 | 6 | The [tutorial branch](https://github.com/eh3rrera/graphql-java-spring-boot-example/tree/tutorial) contains the original demo app. 7 | 8 | You'll need [Java 11 or 17](https://www.oracle.com/java/technologies/downloads/). 9 | 10 | Clone this repo and execute `mvnw spring-boot:run`. Or inside an IDE, execute the class `com.example.DemoGraphQL.DemoGraphQlApplication`. 11 | 12 | To access the database, you can go to [http://localhost:8080/h2-console/login.jsp](http://localhost:8080/h2-console/login.jsp) and enter the following information: 13 | - JDBC URL: jdbc:h2:mem:testdb 14 | - User Name: sa 15 | - Password: 16 | 17 | Or go to [http://localhost:8080/graphiql](http://localhost:8080/graphiql) to start executing queries. For example: 18 | ``` 19 | { 20 | findAllBooks { 21 | id 22 | isbn 23 | title 24 | pageCount 25 | author { 26 | firstName 27 | lastName 28 | } 29 | } 30 | } 31 | ``` 32 | 33 | Or: 34 | ``` 35 | mutation { 36 | newBook( 37 | title: "Java: The Complete Reference, Tenth Edition", 38 | isbn: "1259589331", 39 | author: 1) { 40 | id title 41 | } 42 | } 43 | ``` 44 | 45 | # Extras 46 | 47 | This build demos some UIs hosted at [graphql-java-kickstart](https://github.com/graphql-java-kickstart/graphql-spring-boot). 48 | * Launch with `mvn spring-boot:run` 49 | * Open a browser to view UIs at the following links: 50 | * [GraphiQL](http://localhost:8080/graphiql) 51 | * [Altair](http://localhost:8080/altair) 52 | * [Playground](http://localhost:8080/playground) 53 | * [Voyager](http://localhost:8080/voyager) 54 | 55 | # License 56 | MIT 57 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | DemoGraphQL 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | DemoGraphQL 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.6.3 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 11.1.0 25 | 1.4.200 26 | 1.18.20 27 | 11 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-jpa 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-tomcat 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-configuration-processor 45 | true 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | ${lombok.version} 51 | provided 52 | 53 | 54 | 55 | com.graphql-java-kickstart 56 | graphql-spring-boot-starter 57 | ${graphql.spring.starter.version} 58 | 59 | 60 | com.graphql-java-kickstart 61 | graphiql-spring-boot-starter 62 | ${graphql.spring.starter.version} 63 | runtime 64 | 65 | 66 | com.graphql-java-kickstart 67 | altair-spring-boot-starter 68 | ${graphql.spring.starter.version} 69 | runtime 70 | 71 | 72 | com.graphql-java-kickstart 73 | playground-spring-boot-starter 74 | ${graphql.spring.starter.version} 75 | runtime 76 | 77 | 78 | com.graphql-java-kickstart 79 | voyager-spring-boot-starter 80 | ${graphql.spring.starter.version} 81 | runtime 82 | 83 | 84 | 85 | com.h2database 86 | h2 87 | ${h2.version} 88 | runtime 89 | 90 | 91 | com.github.gavlyukovskiy 92 | p6spy-spring-boot-starter 93 | 1.7.0 94 | 95 | 96 | 97 | org.springframework.boot 98 | spring-boot-starter-test 99 | test 100 | 101 | 102 | com.graphql-java-kickstart 103 | graphql-spring-boot-starter-test 104 | ${graphql.spring.starter.version} 105 | test 106 | 107 | 108 | org.springframework.boot 109 | spring-boot-devtools 110 | true 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | maven-compiler-plugin 119 | 120 | ${java.version} 121 | 122 | 123 | org.projectlombok 124 | lombok 125 | ${lombok.version} 126 | 127 | 128 | org.springframework.boot 129 | spring-boot-configuration-processor 130 | 2.6.3 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | src/main/resources 140 | true 141 | 142 | 143 | 144 | 145 | org.springframework.boot 146 | spring-boot-maven-plugin 147 | 148 | 149 | org.projectlombok 150 | lombok-maven-plugin 151 | ${lombok.version}.0 152 | 153 | 154 | generate-sources 155 | 156 | delombok 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | jdk16 167 | 168 | 16 169 | 170 | 171 | 16 172 | 173 | 174 | 175 | 176 | org.apache.maven.plugins 177 | maven-compiler-plugin 178 | 179 | ${java.version} 180 | 181 | true 182 | 183 | -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED 184 | -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED 185 | -J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED 186 | -J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED 187 | -J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED 188 | -J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED 189 | -J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED 190 | -J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED 191 | -J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 192 | -J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | jcenter 204 | https://jcenter.bintray.com/ 205 | 206 | 207 | 208 | 209 | 210 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/DemoGraphQlApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL; 2 | 3 | import com.example.DemoGraphQL.exception.GraphQLErrorAdapter; 4 | import com.example.DemoGraphQL.model.Author; 5 | import com.example.DemoGraphQL.model.Book; 6 | import com.example.DemoGraphQL.repository.AuthorRepository; 7 | import com.example.DemoGraphQL.repository.BookRepository; 8 | import com.example.DemoGraphQL.resolver.BookResolver; 9 | import com.example.DemoGraphQL.resolver.Mutation; 10 | import com.example.DemoGraphQL.resolver.Query; 11 | import graphql.ExceptionWhileDataFetching; 12 | import graphql.GraphQLError; 13 | import graphql.kickstart.execution.error.GraphQLErrorHandler; 14 | import org.springframework.boot.CommandLineRunner; 15 | import org.springframework.boot.SpringApplication; 16 | import org.springframework.boot.autoconfigure.SpringBootApplication; 17 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 18 | import org.springframework.context.annotation.Bean; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.stream.Collectors; 23 | 24 | @SpringBootApplication 25 | public class DemoGraphQlApplication extends SpringBootServletInitializer { 26 | 27 | public static void main(String[] args) { 28 | SpringApplication.run(DemoGraphQlApplication.class, args); 29 | } 30 | 31 | @Bean 32 | public GraphQLErrorHandler errorHandler() { 33 | return new GraphQLErrorHandler() { 34 | @Override 35 | public List processErrors(List errors) { 36 | List clientErrors = errors.stream() 37 | .filter(this::isClientError) 38 | .collect(Collectors.toList()); 39 | 40 | List serverErrors = errors.stream() 41 | .filter(e -> !isClientError(e)) 42 | .map(GraphQLErrorAdapter::new) 43 | .collect(Collectors.toList()); 44 | 45 | List e = new ArrayList<>(); 46 | e.addAll(clientErrors); 47 | e.addAll(serverErrors); 48 | return e; 49 | } 50 | 51 | protected boolean isClientError(GraphQLError error) { 52 | return !(error instanceof ExceptionWhileDataFetching || error instanceof Throwable); 53 | } 54 | }; 55 | } 56 | 57 | @Bean 58 | public BookResolver authorResolver(AuthorRepository authorRepository) { 59 | return new BookResolver(authorRepository); 60 | } 61 | 62 | @Bean 63 | public Query query(AuthorRepository authorRepository, BookRepository bookRepository) { 64 | return new Query(authorRepository, bookRepository); 65 | } 66 | 67 | @Bean 68 | public Mutation mutation(AuthorRepository authorRepository, BookRepository bookRepository) { 69 | return new Mutation(authorRepository, bookRepository); 70 | } 71 | 72 | @Bean 73 | public CommandLineRunner demo(AuthorRepository authorRepository, BookRepository bookRepository) { 74 | return (args) -> { 75 | Author author = new Author("Herbert", "Schildt"); 76 | authorRepository.save(author); 77 | 78 | bookRepository.save(new Book("Java: A Beginner's Guide, Sixth Edition", "0071809252", 728, author)); 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/MyProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | @ConfigurationProperties("myprops") 7 | @Data 8 | public class MyProperties { 9 | private String version; 10 | private String artifactId; 11 | private H2 h2; 12 | 13 | @Data 14 | public static class H2 { 15 | private String version; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/exception/BookNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.exception; 2 | 3 | import graphql.ErrorType; 4 | import graphql.GraphQLError; 5 | import graphql.language.SourceLocation; 6 | 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class BookNotFoundException extends RuntimeException implements GraphQLError { 12 | 13 | private Map extensions = new HashMap<>(); 14 | 15 | public BookNotFoundException(String message, Long invalidBookId) { 16 | super(message); 17 | extensions.put("invalidBookId", invalidBookId); 18 | } 19 | 20 | @Override 21 | public List getLocations() { 22 | return null; 23 | } 24 | 25 | @Override 26 | public Map getExtensions() { 27 | return extensions; 28 | } 29 | 30 | @Override 31 | public ErrorType getErrorType() { 32 | return ErrorType.DataFetchingException; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/exception/GraphQLErrorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.exception; 2 | 3 | import graphql.ErrorClassification; 4 | import graphql.ExceptionWhileDataFetching; 5 | import graphql.GraphQLError; 6 | import graphql.language.SourceLocation; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class GraphQLErrorAdapter implements GraphQLError { 12 | 13 | private GraphQLError error; 14 | 15 | public GraphQLErrorAdapter(GraphQLError error) { 16 | this.error = error; 17 | } 18 | 19 | @Override 20 | public Map getExtensions() { 21 | return error.getExtensions(); 22 | } 23 | 24 | @Override 25 | public List getLocations() { 26 | return error.getLocations(); 27 | } 28 | 29 | @Override 30 | public ErrorClassification getErrorType() { 31 | return error.getErrorType(); 32 | } 33 | 34 | @Override 35 | public List getPath() { 36 | return error.getPath(); 37 | } 38 | 39 | @Override 40 | public Map toSpecification() { 41 | return error.toSpecification(); 42 | } 43 | 44 | @Override 45 | public String getMessage() { 46 | return (error instanceof ExceptionWhileDataFetching) ? ((ExceptionWhileDataFetching) error).getException().getMessage() : error.getMessage(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/model/Author.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.model; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | public class Author { 7 | @Id 8 | @Column(name="author_id", nullable = false) 9 | @GeneratedValue(strategy=GenerationType.AUTO) 10 | private Long id; 11 | 12 | @Column(name="author_first_name", nullable = false) 13 | private String firstName; 14 | 15 | @Column(name="author_last_name", nullable = false) 16 | private String lastName; 17 | 18 | public Author() { 19 | } 20 | 21 | public Author(Long id) { 22 | this.id = id; 23 | } 24 | 25 | public Author(String firstName, String lastName) { 26 | this.firstName = firstName; 27 | this.lastName = lastName; 28 | } 29 | 30 | public Long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getFirstName() { 39 | return firstName; 40 | } 41 | 42 | public void setFirstName(String firstName) { 43 | this.firstName = firstName; 44 | } 45 | 46 | public String getLastName() { 47 | return lastName; 48 | } 49 | 50 | public void setLastName(String lastName) { 51 | this.lastName = lastName; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) return true; 57 | if (o == null || getClass() != o.getClass()) return false; 58 | 59 | Author author = (Author) o; 60 | 61 | return id.equals(author.id); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return id.hashCode(); 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "Author{" + 72 | "id=" + id + 73 | ", firstName='" + firstName + '\'' + 74 | ", lastName='" + lastName + '\'' + 75 | '}'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.model; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | public class Book { 7 | @Id 8 | @Column(name="book_id", nullable = false) 9 | @GeneratedValue(strategy=GenerationType.AUTO) 10 | private Long id; 11 | 12 | @Column(name="book_title", nullable = false) 13 | private String title; 14 | 15 | @Column(name="book_isbn", nullable = false) 16 | private String isbn; 17 | 18 | @Column(name="book_pageCount", nullable = false) 19 | private int pageCount; 20 | 21 | @ManyToOne 22 | @JoinColumn(name = "author_id", 23 | nullable = false, updatable = false) 24 | private Author author; 25 | 26 | public Book() { 27 | } 28 | 29 | public Book(String title, String isbn, int pageCount, Author author) { 30 | this.title = title; 31 | this.isbn = isbn; 32 | this.pageCount = pageCount; 33 | this.author = author; 34 | } 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getTitle() { 45 | return title; 46 | } 47 | 48 | public void setTitle(String title) { 49 | this.title = title; 50 | } 51 | 52 | public String getIsbn() { 53 | return isbn; 54 | } 55 | 56 | public void setIsbn(String isbn) { 57 | this.isbn = isbn; 58 | } 59 | 60 | public int getPageCount() { 61 | return pageCount; 62 | } 63 | 64 | public void setPageCount(int pageCount) { 65 | this.pageCount = pageCount; 66 | } 67 | 68 | public Author getAuthor() { 69 | return author; 70 | } 71 | 72 | public void setAuthor(Author author) { 73 | this.author = author; 74 | } 75 | 76 | @Override 77 | public boolean equals(Object o) { 78 | if (this == o) return true; 79 | if (o == null || getClass() != o.getClass()) return false; 80 | 81 | Book book = (Book) o; 82 | 83 | return id.equals(book.id); 84 | } 85 | 86 | @Override 87 | public int hashCode() { 88 | return id.hashCode(); 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "Book{" + 94 | "id=" + id + 95 | ", title='" + title + '\'' + 96 | ", isbn='" + isbn + '\'' + 97 | ", pageCount=" + pageCount + 98 | ", author=" + author + 99 | '}'; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/repository/AuthorRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.repository; 2 | 3 | import com.example.DemoGraphQL.model.Author; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface AuthorRepository extends JpaRepository 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.repository; 2 | 3 | import com.example.DemoGraphQL.model.Book; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface BookRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/resolver/BookResolver.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.resolver; 2 | 3 | import com.example.DemoGraphQL.model.Author; 4 | import com.example.DemoGraphQL.model.Book; 5 | import com.example.DemoGraphQL.repository.AuthorRepository; 6 | import graphql.kickstart.tools.GraphQLResolver; 7 | 8 | public class BookResolver implements GraphQLResolver { 9 | private AuthorRepository authorRepository; 10 | 11 | public BookResolver(AuthorRepository authorRepository) { 12 | this.authorRepository = authorRepository; 13 | } 14 | 15 | public Author getAuthor(Book book) { 16 | return authorRepository.findById(book.getAuthor() 17 | .getId()) 18 | .orElseThrow(null); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/resolver/Mutation.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.resolver; 2 | 3 | import com.example.DemoGraphQL.exception.BookNotFoundException; 4 | import com.example.DemoGraphQL.model.Author; 5 | import com.example.DemoGraphQL.model.Book; 6 | import com.example.DemoGraphQL.repository.AuthorRepository; 7 | import com.example.DemoGraphQL.repository.BookRepository; 8 | import graphql.kickstart.tools.GraphQLMutationResolver; 9 | 10 | import java.util.Optional; 11 | 12 | public class Mutation implements GraphQLMutationResolver { 13 | private BookRepository bookRepository; 14 | private AuthorRepository authorRepository; 15 | 16 | public Mutation(AuthorRepository authorRepository, BookRepository bookRepository) { 17 | this.authorRepository = authorRepository; 18 | this.bookRepository = bookRepository; 19 | } 20 | 21 | public Author newAuthor(String firstName, String lastName) { 22 | Author author = new Author(); 23 | author.setFirstName(firstName); 24 | author.setLastName(lastName); 25 | 26 | authorRepository.save(author); 27 | 28 | return author; 29 | } 30 | 31 | public Book newBook(String title, String isbn, Integer pageCount, Long authorId) { 32 | Book book = new Book(); 33 | book.setAuthor(new Author(authorId)); 34 | book.setTitle(title); 35 | book.setIsbn(isbn); 36 | book.setPageCount(pageCount != null ? pageCount : 0); 37 | 38 | bookRepository.save(book); 39 | 40 | return book; 41 | } 42 | 43 | public boolean deleteBook(Long id) { 44 | bookRepository.deleteById(id); 45 | return true; 46 | } 47 | 48 | public Book updateBookPageCount(Integer pageCount, Long id) { 49 | Optional opt = bookRepository.findById(id); 50 | if (opt.isPresent()) { 51 | Book book = opt.get(); 52 | book.setPageCount(pageCount); 53 | bookRepository.save(book); 54 | return book; 55 | } 56 | throw new BookNotFoundException("The book to be updated was found", id); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/example/DemoGraphQL/resolver/Query.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.resolver; 2 | 3 | import com.example.DemoGraphQL.model.Author; 4 | import com.example.DemoGraphQL.model.Book; 5 | import com.example.DemoGraphQL.repository.AuthorRepository; 6 | import com.example.DemoGraphQL.repository.BookRepository; 7 | import graphql.kickstart.tools.GraphQLQueryResolver; 8 | 9 | public class Query implements GraphQLQueryResolver { 10 | private BookRepository bookRepository; 11 | private AuthorRepository authorRepository; 12 | 13 | public Query(AuthorRepository authorRepository, BookRepository bookRepository) { 14 | this.authorRepository = authorRepository; 15 | this.bookRepository = bookRepository; 16 | } 17 | 18 | public Iterable findAllBooks() { 19 | return bookRepository.findAll(); 20 | } 21 | 22 | public long countBooks() { 23 | return bookRepository.count(); 24 | } 25 | 26 | public Iterable findAllAuthors() { 27 | return authorRepository.findAll(); 28 | } 29 | 30 | public long countAuthors() { 31 | return authorRepository.count(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | graphql: 2 | servlet: 3 | mapping: /graphql 4 | myprops: 5 | artifactId: '@project.artifactId@' 6 | version: '@project.version@' 7 | h2: 8 | version: '@h2.version@' 9 | spring: 10 | datasource: 11 | url: jdbc:h2:mem:testdb;TRACE_LEVEL_FILE=3 12 | username: sa 13 | password: '' 14 | driverClassName: org.h2.Driver 15 | initialization-mode: embedded 16 | h2: 17 | console: 18 | enabled: true 19 | path: /h2-console 20 | jpa: 21 | database-platform: org.hibernate.dialect.H2Dialect 22 | hibernate: 23 | ddl-auto: update 24 | properties.hibernate.jdbc.time_zone: UTC 25 | show-sql: false 26 | 27 | voyager: 28 | mapping: /voyager 29 | 30 | logging: 31 | level: 32 | org.hibernate.SQL: WARN 33 | decorator: 34 | datasource: 35 | p6spy: # logging SQL after binding parameters 36 | enable-logging: true 37 | multiline: true 38 | logging: sysout 39 | log-format: '%(sql)' -------------------------------------------------------------------------------- /src/main/resources/graphql/author.graphqls: -------------------------------------------------------------------------------- 1 | type Author { 2 | id: ID! 3 | firstName: String! 4 | lastName: String! 5 | } 6 | 7 | type Query { 8 | findAllAuthors: [Author]! 9 | countAuthors: Int! 10 | } 11 | 12 | type Mutation { 13 | newAuthor(firstName: String!, lastName: String!) : Author! 14 | } -------------------------------------------------------------------------------- /src/main/resources/graphql/book.graphqls: -------------------------------------------------------------------------------- 1 | type Book { 2 | id: ID! 3 | title: String! 4 | isbn: String! 5 | pageCount: Int 6 | author: Author 7 | } 8 | 9 | extend type Query { 10 | findAllBooks: [Book]! 11 | countBooks: Int! 12 | } 13 | 14 | extend type Mutation { 15 | newBook(title: String!, isbn: String!, pageCount: Int, author: ID!) : Book! 16 | deleteBook(id: ID!) : Boolean 17 | updateBookPageCount(pageCount: Int!, id: ID!) : Book! 18 | } -------------------------------------------------------------------------------- /src/test/java/com/example/DemoGraphQL/DemoGraphQlApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.boot.test.web.client.TestRestTemplate; 10 | import org.springframework.jdbc.core.JdbcTemplate; 11 | import org.springframework.test.context.junit.jupiter.SpringExtension; 12 | 13 | import javax.sql.DataSource; 14 | import java.io.IOException; 15 | import java.sql.Connection; 16 | import java.sql.ResultSet; 17 | import java.sql.SQLException; 18 | import java.sql.Statement; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | import static org.junit.jupiter.api.Assertions.assertNotNull; 22 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 23 | 24 | @ExtendWith(SpringExtension.class) 25 | @SpringBootTest(webEnvironment = RANDOM_PORT, classes = DemoGraphQlApplicationTests.Config.class) 26 | @EnableAutoConfiguration 27 | @EnableConfigurationProperties(MyProperties.class) 28 | public class DemoGraphQlApplicationTests { 29 | @Autowired 30 | MyProperties properties; 31 | 32 | @Autowired 33 | JdbcTemplate jdbcTemplate; 34 | 35 | @Autowired 36 | DataSource dataSource; 37 | 38 | static class Config {} 39 | 40 | @Autowired 41 | private TestRestTemplate restTemplate; 42 | 43 | @Test 44 | public void contextLoads() { 45 | assertNotNull(restTemplate); 46 | assertNotNull(jdbcTemplate); 47 | assertNotNull(dataSource); 48 | } 49 | 50 | @Test 51 | public void h2Connection() throws SQLException { 52 | try (Connection conn = dataSource.getConnection()) { //DriverManager.getConnection("jdbc:h2:~/test", "sa", "")) { 53 | assertNotNull(conn); 54 | Statement st = conn.createStatement(); 55 | ResultSet rs = st.executeQuery("SELECT 1"); 56 | assertThat(rs).isNotNull(); 57 | } 58 | } 59 | 60 | @Test 61 | public void h2Version() { 62 | String actualVersion = jdbcTemplate.queryForObject("SELECT `VALUE` FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME = 'CREATE_BUILD'", String.class); 63 | String expectedVersion = properties.getH2() 64 | .getVersion(); 65 | assertThat(expectedVersion).endsWith("." + actualVersion); // the db must be created with the same h2 version in our build 66 | } 67 | 68 | @Test 69 | public void artifactProperty() throws IOException { 70 | assertThat(properties.getArtifactId()).isEqualTo("DemoGraphQL"); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/example/DemoGraphQL/resolver/QueryTest.java: -------------------------------------------------------------------------------- 1 | package com.example.DemoGraphQL.resolver; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit.jupiter.SpringExtension; 8 | 9 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 10 | 11 | @ExtendWith(SpringExtension.class) 12 | @SpringBootTest(webEnvironment = RANDOM_PORT) 13 | @EnableAutoConfiguration 14 | class QueryTest 15 | { 16 | @Test 17 | public void test() { 18 | 19 | } 20 | 21 | 22 | } --------------------------------------------------------------------------------