Git Product home page Git Product logo

spring-petclinic-graphql's Introduction

PetClinic Sample Application using Spring for GraphQL

This PetClinic example uses Spring for GraphQL, that is part of Spring Boot since version 2.7.

It implements a GraphQL API for the PetClinic and provides an example Frontend for the API.

Versions currently in use are Spring Boot 3.2.x and Spring for GraphQL 1.2.x.

Java CI with Maven

Open in Gitpod

Features

Some features that are built in:

  • Annotated Controllers (see graphql/*Controller-classes, e.g. SpecialtyController and VetController)
  • Subscriptions via Websockets (see VisitController#onNewVisit) including integration test (see VisitSubscriptionTest) and examples below
  • Own scalar types (See PetClinicRuntimeWiringConfiguration and DateCoercing)
  • GraphQL Interfaces (GraphQL Type Person) and Unions (GraphQL Type AddVetPayload), see class PetClinicRuntimeWiringConfiguration
  • Security: the /graphql http and WebSocket endpoints are secured and can only be accessed using a JWT token. More fine grained security is implemented using @PreAuthorize (see VetService)
    • Example: addVet mutation is only allowed for users with ROLE_MANAGER
  • Pagination, Filtering and Sorting of results: Implemented using the Pagination support of Spring GraphQL, see OwnerController. The result of the owners field is a Connection object defined in the Cursor Connection specification.
    • The Apollo client in the React frontend uses the relayStylePagination helper function to automatically manage the Client-side cache with new objects read using the after cursor query argument. (See OwnerSearchPage.tsx)
  • Custom GraphiQL Build, that has its own login screen, since the PetClinic GraphQL is only accessible with a Token
    • see project petclinic-graphiql
  • Tests: See test folder for typical GraphQL endpoint tests, including tests for security
  • End-to-end browser tests: see e2e-tests folder for some Playwright based end-to-end tests that test the running application in a real browser. Read description below how to run the tests.
  • GitHub action workflow:
    • builds and tests the backend
    • starts the backend including database with docker-compose to run the end-to-end-tests
    • (see .github/workflows/build-app.yml)

Running the sample application

You can run the sample application with two ways:

  1. The easiest way: run it pre-configured in cloud IDE GitPod
  2. Run it locally

Run it in GitPod

To run the application (backend, GraphiQL and React frontend) in GitPod, simply click on the "Open in GitPod" button at the top of this README.

  • Note that you need a (free) GitPod account.
  • And please make sure that you allow your browser opening new tabs/windows from gitpod.io!

After clicking on the GitPod button, GitPod creates a new workspace including an Editor for you, builds the application and starts backend and frontend. That might take some time!

When backend and frontend are running, GitPod opens two new browser tabs, one with GraphiQL and one with the PetClinic backend. For login options, see below "Accessing the GraphQL API"

Note that the workspace is your personal workspace, you can make changes, save files, re-open the workspace at any time and you can even create git commits and pull requests from it. For more information see GitPod documentation.

In the GitPod editor you can make changes to the app, and after saving the app will be recompiled and redeployed automatically.

SpringBoot PetClinic in GitPod Workspace

Using IntelliJ with GitPod

Recently GitPod has added support for JetBrain IDEs like IntelliJ. While this support is currenty beta only, you can try it and open the PetClinic in IntelliJ. Note that in this scenario you're still working on a complete, ready-to-use workspace in the cloud. Only the IntelliJ UI runs locally at your maching.

Please read the setup instructions here.

SpringBoot PetClinic in GitPod IntelliJ Workspace

Running locally

The server is implemented in the backend folder and can be started either from your IDE (org.springframework.samples.petclinic.PetClinicApplication) or using maven from the root folder of the repository:

./mvnw spring-boot:run -pl backend

Note: the server runs on port 9977, so make sure, this port is available.

  • Note: you need to have docker installed. docker-compose needs to be in your path
  • On startup the server uses Spring Boot docker compose support to run the required postgres database

Running the frontend

While you can access the whole GraphQL API from GraphiQL this demo application also contains a modified version of the classic PetClinic UI. Compared to the original client this client is built as a Single-Page-Application using React and Apollo GraphQL and has slightly different features to make it a more realistic use-case for GraphQL.

You can install and start the frontend by using pnpm:

cd ./frontend

pnpm install

pnpm codegen

pnpm start

The running frontend can be accessed on http://localhost:3080.

For valid users to login, see list above.

SpringBoot PetClinic, React Frontend

Deployment

There are two scenarios: local development environment and "production" environment

Local development

In local development:

  • the backend runs on http://localhost:9977 (GraphQL API and graphiql)
  • the Vite development server for the frontend runs on http://localhost:3080
  • the postgres database is started automatically by Spring Boot using the docker-compose.yml file in the root folder

In this scenario, the vite server acts also as a reverse proxy, that proxies all requests to /api, /graphql and /graphqlws to the backend server (localhost:9977). The proxy is configured in frontend/vite.config.ts

If you like you can run the customized graphiql with its own Vite development server (using pnpm dev in petclinic-graphiql) that runs on http://localhost:3081. This is handy if you want to make changes to GraphiQL.

"Production" environment

In this setup, the backend and frontend process run as docker containers using a docker-compose setup that is described in docker-compose-petclinic.yml:

Here the nginx acts as the proxy to the backend.

You can build the docker images for backend and frontend using the build-local.sh scripts. Also, these images are build during the GitHub workflow.

Accessing the GraphQL API

You can access the GraphQL API via the included customized version of GraphiQL.

The included GraphiQL adds support for login to the original GraphiQL.

You can use the following users for login:

  • joe/joe: Regular user
  • susi/susi: has Manager Role and is allowed to execute the createVet Mutation

After starting the server, GraphiQL runs on http://localhost:9977

Sample Queries

Here you can find some sample queries that you can copy+paste and run in GraphiQL. Feel free to explore and try more ๐Ÿ˜Š.

Query find first 2 owners whose lastname starts with "D" and their pets, order by lastname and firstname

  query {
    owners(
      first: 2
      filter: { lastName: "d" }
      order: [{ field: lastName }, { field: firstName, direction: DESC }]
    ) {
      edges {
        cursor
        node {
          id
          firstName
          lastName
          pets {
            id
            name
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }

The following query should return two items, but we have more then two owners in the database staring with a d. Thus, the pageInfo.hasNextPage-field returned in the result of the query above is true and the endCursor points to the last object returned. Using this cursor as after we can receive the next batch of Owners:

  query {
    owners(
      first: 2
      after: "T18y"
      filter: { lastName: "d" }
      order: [{ field: lastName }, { field: firstName, direction: DESC }]
    ) {
      edges {
        cursor
        node {
          id
          firstName
          lastName
          pets {
            id
            name
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }

Add a new Visit using a mutation (can be done with user joe and susi) and read id and pet of the new created visit:

mutation {
    addVisit(input:{
        petId:3,
        description:"Check teeth",
        date:"2022/03/30",
        vetId:1
    }) {
        newVisit:visit {
            id
            pet {
                id 
                name 
                birthDate
            }
        }
    }
}

Add a new veterinarian. This is only allowed for users with ROLE_MANAGER and that is susi:

mutation {
  addVet(input: {
      firstName: "Dagmar", 
      lastName: "Smith", 
      specialtyIds: [1, 3]}) {
      
    ... on AddVetSuccessPayload {
      newVet: vet {
        id
        specialties {
          id
          name
        }
      }
    }
      
    ... on AddVetErrorPayload {
      error
    }
  }
}

Listen for new visits using a Subscription

This mutation selects the treating veterinarian of the new created Visit and the pet that will be visiting. You can either create a new Visit using the mutation above or using the frontend application.

subscription {
    onNewVisit {
        description
        treatingVet {
            id
            firstName
            lastName
        }
        pet {
            id
            name
        }
    }

}

Note: In the frontend application, you can open an Owner an see all its pets including their visits. If you add a new visit to one of the pets, in all other browser windows that have the Owner page with that Owner open, the new visit should be added to the table automatically, because the OwnerPage React component uses a subscription to update the table contents in the background.

SpringBoot PetClinic, GraphiQL

Customized GraphiQL

The backend includes a Spring Petclinic-specific customized version of GraphiQL. Compared to GraphiQL that is embedded by default, the customized version has a login form so that it can send JWT Authentication header with each request to the GraphQL backend.

Please see the subproject petclinic-graphiql for more information.

End-to-end tests

Inside the folder e2e-tests you find some Playwright-based end-to-end tests.

To run the test, please make sure, the backend and the frontend processes are running, as described above.

Then install playwright and all its dependencies including the required browsers by running

cd e2e-tests
pnpm install

Then you can use pnpm to start the test:

  • pnpm test will execute all tests in headless mode in all three configured browsers (Chrome, Firefox, Safari)

  • pnpm test:ui opens the tests in Playwright's UI mode

    • From the started Playwright UI you can individually select which test to run in which browser
    • You can also debug the tests from there
  • pnpm test:headed: runs the tests in a headed (i.e. visible) browser (by default Chrome).

  • pnpm test:docker-compose runs the test agains the docker-compose-based setup (localhost:3090/localhost:3091)

Running, debugging and developing the tests

For writing and running Playwright tests I prefer VS code with the Playwright extension

But if you want to develop and run the tests in IntelliJ, you can install the Test Automation Plug-in by Jetbrains.

Contributing

If you like to help and contribute you're more than welcome! Please open an issue or a Pull Request

Initial implementation of this GraphQL-based PetClinic example: Nils Hartmann, Twitter

spring-petclinic-graphql's People

Contributors

arey avatar babinslava avatar boly38 avatar bram-atmire avatar cbeams avatar colinbut avatar craigsdennis avatar cyrille-leclerc avatar dependabot[bot] avatar freemansoft avatar gordonad avatar helloworld123122344134 avatar liouxiao avatar lukasz-szewc avatar meltsufin avatar mklose avatar nilshartmann avatar patrickcrocker avatar rstoyanchev avatar srbala avatar srenkens avatar tduchateau avatar tejasm avatar thinkshihang avatar trepel avatar verydapeng avatar vfedoriv avatar vladfau 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  avatar

Watchers

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

spring-petclinic-graphql's Issues

Incompatible with Java 11

./mvnw spring-boot:run run just fine on Java 8 but fails on 11 version with:

$ ./mvnw spring-boot:run
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dsun.java2d.pmoffscreen=false -XX:+UseCompressedOops -XX:+DoEscapeAnalysis -XX:+AggressiveOpts -XX:+EliminateLocks -XX:+UseNUMA -XX:+TieredCompilation
OpenJDK 64-Bit Server VM warning: Option AggressiveOpts was deprecated in version 11.0 and will likely be removed in a future release.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building petclinic 2.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.0.1.RELEASE:run (default-cli) > test-compile @ spring-petclinic >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ spring-petclinic ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 11 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ spring-petclinic ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 83 source files to /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[18,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[19,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[29,2] cannot find symbol
  symbol: class XmlRootElement
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vet.java:[23,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[34,6] cannot find symbol
  symbol:   class XmlElement
  location: class org.springframework.samples.petclinic.model.Vets
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vet.java:[55,6] cannot find symbol
  symbol:   class XmlElement
  location: class org.springframework.samples.petclinic.model.Vet
[INFO] 6 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.110 s
[INFO] Finished at: 2019-02-09T23:24:33+03:00
[INFO] Final Memory: 32M/148M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-petclinic: Compilation failure: Compilation failure:
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[18,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[19,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[29,2] cannot find symbol
[ERROR] symbol: class XmlRootElement
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vet.java:[23,33] package javax.xml.bind.annotation does not exist
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vets.java:[34,6] cannot find symbol
[ERROR] symbol:   class XmlElement
[ERROR] location: class org.springframework.samples.petclinic.model.Vets
[ERROR] /home/pasha/@Projects/@Senso/webapp.spring-petclinic-graphql/backend/src/main/java/org/springframework/samples/petclinic/model/Vet.java:[55,6] cannot find symbol
[ERROR] symbol:   class XmlElement
[ERROR] location: class org.springframework.samples.petclinic.model.Vet
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Incorrect Package Name

package org.springframework.samples.petclinic.service;
Change this to - package org.springframework.samples.petclinic.repository;

Please add me to this project contributor. I would like to contribute.

License

Hi! I'm having trouble finding out what license this code is released under. In one other project in this org I saw that it was Apache 2.0. Does this have that license too? If so, could a license file be added?

Thanks!

Drop frontend for spring-graphql version?

Hi,

I'm going to upgrade the spring-graphql branch to latest spring boot and spring-graphql versions soon (waiting for SB 2.7.0 M3 to be released).

And now I'm wondering, if we should remove the react frontend from the example at all and only provide the backend (like spring-petclinic-rest is doing).

Reasons:

  1. If one wants to have an example for spring-graphql the backend is enough, we can enable graphiql, so anyone can try the graphql API without a "real" frontend.
  2. We can focus on the backend, add more examples, maybe even some more "real-world" usecases (for example perforamnce optimization, integrating other APIs etc)
  3. The current frontend is React and Apollo specific. While this is not an uncommon setup imho (Java/Spring + React + Apollo) it's not a setup everyone uses. Others are using Angular or Vue or using other GraphQL client frameworks than Apollo... So the frontend only helps some people and also it doesn't help understanding spring-graphql at all (I think).

As an alternative we could provide frontends in own projects, as the spring-petclinic-angular project is doing for the spring-petclinic-rest backend.

I really enjoyed building the React frontend and still think it's a good demonstration of a powerful tech stack, I think it's too much for this spring-petclinic-graphql example ๐Ÿ˜ข

What do you think?

Login page error

I could not compile and run the front-end application. The LoginPage.tsx would not compile giving
} catch (err) {
console.error("LOGIN FAILED ================ >>>>>>>>>>>>>>>>> ", err);
setLoginRequestState({ error: err.message });
}

at line 54,34

I do get login screen after npm start but application crashed

Failed to run backend as WAR package

I was able to run the backend using Maven: mvnw spring-boot:run. Now I have this requirement to deploy it to Apache TOMCAT server with context path /petclinic.

When I test the connection to graphql using url /petclinic/graphql, it just returns 404 error. I have changed the settings in application.properties as:
graphql.servlet.mapping=/petclinic/graphql

Do I miss out any configuration?

Convert to Kotlin

Another change is from Java, pl. use kotlin again as it is latest.

npm install -> errors

xxx@pop-os:~/projects/tests/spring-petclinic-graphql/frontend$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR! typescript@"^4.1.3" from the root project
npm ERR! peer typescript@">=2.7" from [email protected]
npm ERR! node_modules/ts-node
npm ERR! ts-node@"^9" from @endemolshinegroup/[email protected]
npm ERR! node_modules/@endemolshinegroup/cosmiconfig-typescript-loader
npm ERR! @endemolshinegroup/cosmiconfig-typescript-loader@"3.0.2" from [email protected]
npm ERR! node_modules/graphql-config
npm ERR! graphql-config@"^3.2.0" from @graphql-codegen/[email protected]
npm ERR! node_modules/@graphql-codegen/cli
npm ERR! peerOptional ts-node@">=9.0.0" from [email protected]
npm ERR! node_modules/jest-config
npm ERR! jest-config@"^26.6.3" from @jest/[email protected]
npm ERR! node_modules/@jest/core
npm ERR! @jest/core@"^26.6.0" from [email protected]
npm ERR! node_modules/jest
npm ERR! 1 more (jest-cli)
npm ERR! 3 more (jest-runner, jest-runtime, jest-cli)
npm ERR! 1 more (tsutils)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1" from [email protected]
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"4.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/typescript
npm ERR! peerOptional typescript@"^3.2.1" from [email protected]
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"4.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xxxj/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/xxx/.npm/_logs/2022-06-18T20_13_33_959Z-debug-0.log

deploy WAR to weblogic

Hi,

I'm trying to deploy this demo app to weblogic 12c but failed to start it:

INFO AutoConfigurationReportLoggingInitializer -

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
ERROR SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServletRegistrationBean' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServletRegistrationBean' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLServlet' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLServlet' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchemaProvider' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchemaProvider' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLSchema' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLJavaToolsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLSchema' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaParser' defined in class path resource [com/oembedler/moon/graphql/boot/GraphQLJavaToolsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is java.lang.IllegalStateException: No *.graphqls files found on classpath. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)

To support weblogic, I also made a few changes:

  1. change the main application as:
    public class PetClinicApplication extends SpringBootServletInitializer implements WebApplicationInitializer {...}

  2. add weblogic.xml to resolve the dependency conflicts:
    <wls:weblogic-web-app
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
    http://xmlns.oracle.com/weblogic/weblogic-web-app
    http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">

    wls:container-descriptor
    wls:prefer-web-inf-classestrue</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
    </wls:weblogic-web-app>

but the same WAR file can be deployed to TOMCAT and start it successfully. I also check the source code GraphQLJavaToolsAutoConfiguration.java which loads the files:
Resource[] resources = applicationContext.getResources("classpath*:**/*.graphqls");
if(resources.length <= 0) {
throw new IllegalStateException("No *.graphqls files found on classpath. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.");
}

Example with "Microservice" and DataLoader

Hi @arey and all!

I created another variation of the spring-petclinic-graphql example, that I needed for trainings and other demonstrations.

This version uses a second backend "micro service" (for managing Vets) that can be used to demonstrate working of DataLoaders when collecting data for a GraphQL response from other remote services.

Everything else is almost the same as in our current example. Do you think I should merge the "new" example to this repository? I think it's a more realistic example with two backend services and it's also important to have a DataLoader example.

You can find my repo here: https://github.com/nilshartmann/spring-petclinic-graphql-microservice

If interessted, I would merge that back into this repo.

Thanks,
Nils

Running backend locally fails

Dear Nils,
when I'm trying to run the backend project locally as described i get an error.

The project builds correctly but when it's supposed to start i get:

`2023-12-05T23:46:30.925+01:00 ERROR 26962 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.boot.docker.compose.core.ProcessExitException: 'docker-compose version --format json' failed with exit code 1.

Stdout:

Stderr:
Show version information

Usage: version [--short]

Options:
--short Shows only Compose's version number.

at org.springframework.boot.docker.compose.core.ProcessRunner.run(ProcessRunner.java:96) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.core.ProcessRunner.run(ProcessRunner.java:74) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.getDockerComposeCommand(DockerCli.java:165) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.core.DockerCli$DockerCommands.<init>(DockerCli.java:130) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.core.DockerCli.lambda$new$0(DockerCli.java:65) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220) ~[na:na]
at org.springframework.boot.docker.compose.core.DockerCli.<init>(DockerCli.java:64) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.core.DockerCompose.get(DockerCompose.java:92) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getDockerCompose(DockerComposeLifecycleManager.java:149) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:110) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.2.0.jar:3.2.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:149) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:137) ~[spring-context-6.1.1.jar:6.1.1]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.2.0.jar:3.2.0]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:431) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331) ~[spring-boot-3.2.0.jar:3.2.0]
at org.springframework.samples.petclinic.PetClinicApplication.main(PetClinicApplication.java:13) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.2.0.jar:3.2.0]

`

Do you have any idea what is causing it?
I'm running linux and docker-composer is installed.

Kim

spring-graphql example

Hi,

on the branch spring-graphql I started implementing an example based on the recently announced new spring-graphql project.

I wonder if we:

  1. should replace the existing example (that uses the outdated graphql-java-tools lib, that is now graphql-java-kickstart with the spring-graphql-based one (merge spring-graphql-branch to master)
  2. or if we should create a new GitHub repo with the new example spring-graphql-example.

Myself, I'm unsure, but tend to option 1, as the current example is outdated anyway (and we can create an own branch for that example to make it still accessible for everyone) and spring-graphql might become the "offcial" GraphQL solution for spring anyway in the near future.

What do you think?

Best,
Nils

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.