Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions blog/2021-02-12-spec-releases-are-not-important.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,3 @@ It is better to think about certain features you want to discuss instead referri

# Feedback or questions
We use [GitHub Discussions](https://github.com/graphql-java/graphql-java/discussions) for general feedback and questions.

You can also contact us on Twitter: [@graphql_java](https://twitter.com/graphql_java)
2 changes: 1 addition & 1 deletion blog/2021-08-03-17-released-and-lts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Going forward we decided to no offer any LTS versions anymore. We will only acti
the latest version (currently 17). We may backport critical bugfixes, but we are not committed to it.

If this is a huge problem for you or your Company and you are willing to help us with maintaining a LTS
version you can reach us at Twitter [GraphQL Java](https://twitter.com/graphql_java) or per mail at
version you can reach us via email at
hello at graphql-java dot com.
4 changes: 0 additions & 4 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ const config = {
label: 'GitHub Discussions',
href: 'https://github.com/graphql-java/graphql-java/discussions',
},
{
label: 'Twitter',
href: 'https://twitter.com/graphql_java',
},
],
},
{
Expand Down
70 changes: 0 additions & 70 deletions src/components/HomepageFeatures.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/HomepageFeatures.module.css

This file was deleted.

4 changes: 1 addition & 3 deletions src/pages/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ hide_table_of_contents: true

# About

The GraphQL Java project is run by [Andreas Marek](https://twitter.com/andimarek) and [Brad Baker](https://github.com/bbakerman).
The GraphQL Java project is run by [Andreas Marek](https://github.com/andimarek), [Brad Baker](https://github.com/bbakerman), and [Donna Zhou](https://github.com/dondonz).

Andreas Marek is responsible for the content of this website.

You can also follow [GraphQL Java on Twitter](https://twitter.com/graphql_java).
4 changes: 0 additions & 4 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css';
import HomepageFeatures from '../components/HomepageFeatures';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
Expand Down Expand Up @@ -32,9 +31,6 @@ export default function Home() {
title={`Hello from ${siteConfig.title}`}
description="GraphQL Java home page">
<HomepageHeader />
{/*<main>*/}
{/*<HomepageFeatures />*/}
{/*</main>*/}
</Layout>
);
}
102 changes: 45 additions & 57 deletions src/pages/tutorials/getting-started-with-spring-boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ id: tutorial-getting-started
---
# Getting started with Spring for GraphQL

In this tutorial, you will create a GraphQL server in Java using [Spring for GraphQL](https://docs.spring.io/spring-graphql/docs/current/reference/html/). It requires a little Spring and Java knowledge. While we give a brief introduction to GraphQL, the focus of this tutorial is developing a GraphQL server in Java.
In this tutorial, you will create a GraphQL server in Java using [Spring for GraphQL](https://docs.spring.io/spring-graphql/reference/) in 3 minutes. It requires a little Spring and Java knowledge. While we give a brief introduction to GraphQL, the focus of this tutorial is developing a GraphQL server in Java.

If you're looking to learn more after this tutorial, we (the maintainers) have written a book! [**GraphQL with Java and Spring**](https://leanpub.com/graphql-java) includes everything you need to know to build a production ready GraphQL service with Spring for GraphQL, the official Spring integration built on top of the GraphQL Java engine. It's available on [Leanpub](https://leanpub.com/graphql-java) and [Amazon](https://www.amazon.com/GraphQL-Java-Spring-Andreas-Marek-ebook/dp/B0C96ZYWPF/).

Expand Down Expand Up @@ -85,7 +85,7 @@ We've barely scratched the surface of what's possible with GraphQL. Further info
[GraphQL Java](https://www.graphql-java.com) is the Java (server) implementation for GraphQL.
There are several repositories in the GraphQL Java Github org. The most important one is the [GraphQL Java Engine](https://github.com/graphql-java/graphql-java) which is the basis for everything else.

The GraphQL Java Engine is only concerned with executing queries. It doesn't deal with any HTTP or JSON related topics. For these aspects, we will use [Spring for GraphQL](https://docs.spring.io/spring-graphql/docs/current/reference/html/) which takes care of exposing our API via Spring Boot over HTTP.
The GraphQL Java Engine is only concerned with executing queries. It doesn't deal with any HTTP or JSON related topics. For these aspects, we will use [Spring for GraphQL](https://docs.spring.io/spring-graphql/reference/) which takes care of exposing our API via Spring Boot over HTTP.

The main steps of creating a GraphQL Java server are:

Expand All @@ -104,17 +104,17 @@ The easiest way to create a Spring Boot app is to use the [Spring Initializr](ht
Select:

- Gradle Project
- Java
- Spring Boot 2.7.x
- Spring Boot 3
- Java 17 or higher

For the project metadata, use:

- Group: `com.graphql-java.tutorial`
- Group: `com.graphqljava.tutorial`
- Artifact: `bookDetails`

For dependencies, use:
For dependencies, select:

- Spring Web
- Spring Web, and
- Spring for GraphQL

Then click on `Generate` for a ready to use Spring Boot app.
Expand All @@ -124,8 +124,6 @@ Spring for GraphQL adds many useful features including loading schema files, ini

## Schema

Create a directory `src/main/resources/graphql`.

Add a new file `schema.graphqls` to `src/main/resources/graphql` with the following content:

```graphql
Expand Down Expand Up @@ -160,92 +158,81 @@ It is very important to understand that GraphQL doesn't dictate in any way where
This is the power of GraphQL: it can come from a static in-memory list, from a database or an external service.

### Create the Book class

Add the following to `bookDetails/Book.java`
```java
public class Book {

private String id;
private String name;
private int pageCount;
private String authorId;

public Book(String id, String name, int pageCount, String authorId) {
this.id = id;
this.name = name;
this.pageCount = pageCount;
this.authorId = authorId;
}

package com.graphqljava.tutorial.bookDetails;

import java.util.Arrays;
import java.util.List;

record Book(String id, String name, int pageCount, String authorId) {

private static List<Book> books = Arrays.asList(
new Book("book-1", "Harry Potter and the Philosopher's Stone", 223, "author-1"),
new Book("book-2", "Moby Dick", 635, "author-2"),
new Book("book-3", "Interview with the vampire", 371, "author-3")
new Book("book-1", "Harry Potter and the Philosopher's Stone", 223, "author-1"),
new Book("book-2", "Moby Dick", 635, "author-2"),
new Book("book-3", "Interview with the vampire", 371, "author-3")
);

public static Book getById(String id) {
return books.stream().filter(book -> book.getId().equals(id)).findFirst().orElse(null);
}

public String getId() {
return id;
return books.stream().filter(book -> book.id().equals(id)).findFirst().orElse(null);
}

public String getAuthorId() {
return authorId;
}
}
```

### Create the Author class
Add the following to `bookDetails/Author.java`
```java
public class Author {
package com.graphqljava.tutorial.bookDetails;

private String id;
private String firstName;
private String lastName;
import java.util.Arrays;
import java.util.List;

public Author(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
record Author(String id, String firstName, String lastName) {

private static List<Author> authors = Arrays.asList(
new Author("author-1", "Joanne", "Rowling"),
new Author("author-2", "Herman", "Melville"),
new Author("author-3", "Anne", "Rice")
new Author("author-1", "Joanne", "Rowling"),
new Author("author-2", "Herman", "Melville"),
new Author("author-3", "Anne", "Rice")
);

public static Author getById(String id) {
return authors.stream().filter(author -> author.getId().equals(id)).findFirst().orElse(null);
return authors.stream().filter(author -> author.id().equals(id)).findFirst().orElse(null);
}

public String getId() {
return id;
}
}
```

## Adding code to fetch data
Spring for GraphQL provides an [annotation-based programming model](https://docs.spring.io/spring-graphql/docs/current/reference/html/#controllers) to declare handler methods to fetch the data for specific GraphQL fields.
Spring for GraphQL provides an [annotation-based programming model](https://docs.spring.io/spring-graphql/reference/controllers.html) to declare handler methods to fetch the data for specific GraphQL fields.

Add the following to `bookDetails/BookController.java`

```java
package com.graphqljava.tutorial.bookDetails;

import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.stereotype.Controller;

@Controller
public class BookController {
class BookController {

@QueryMapping
public Book bookById(@Argument String id) {
return Book.getById(id);
}

@SchemaMapping
public Author author(Book book) {
return Author.getById(book.getAuthorId());
return Author.getById(book.authorId());
}

}
```

The `@QueryMapping` annotation binds this method to a query, a field under the Query type.
The query field is then determined from the method name, `bookById`. It could also be declared on the annotation.
Spring for GraphQL uses `RuntimeWiring.Builder` to register the handler method as a `graphql.schema.DataFetcher` for the query field `bookById`.
Expand All @@ -259,7 +246,7 @@ The `@SchemaMapping` annotation maps a handler method to a field in the GraphQL
The field name defaults to the method name, and the type name defaults to the simple class name of the source/parent object injected into the method. In this example, the field defaults to `author` and the type defaults to `Book`.
The type and field can be specified in the annotation.

For more, see the [documentation for the Spring for GraphQL annotated controller feature](https://docs.spring.io/spring-graphql/docs/current/reference/html/#controllers).
For more, see the [documentation for the Spring for GraphQL annotated controller feature](https://docs.spring.io/spring-graphql/reference/controllers.html).

That's all the code we need! Let's run our first query.

Expand All @@ -270,9 +257,10 @@ GraphiQL is a useful visual interface for writing and executing queries, and muc

```
spring.graphql.graphiql.enabled=true
spring.graphql.graphiql.path=/graphiql
```

This will enable GraphiQL at the path `/graphiql` by default. You can change this path by configuring `spring.graphql.graphiql.path`.

### Boot the application
Start your Spring application.

Expand Down Expand Up @@ -304,7 +292,7 @@ With the help of Spring for GraphQL features, we were able to achieve this with

## Further reading
### Book
If you want to learn more, we have written a book! [**GraphQL with Java and Spring**](https://leanpub.com/graphql-java) includes everything you need to know to build a production ready GraphQL service with Spring for GraphQL and GraphQL Java.
If you want to learn more, we (the maintainers) have written a book! [**GraphQL with Java and Spring**](https://leanpub.com/graphql-java) includes everything you need to know to build a production ready GraphQL service with Spring for GraphQL and GraphQL Java.

Learn first-hand from the founder of GraphQL Java and co-author of Spring for GraphQL. The book is suitable for beginners and also includes advanced topics for intermediate readers. The book is available on [Leanpub](https://leanpub.com/graphql-java) and [Amazon](https://www.amazon.com/GraphQL-Java-Spring-Andreas-Marek-ebook/dp/B0C96ZYWPF/).

Expand All @@ -315,7 +303,7 @@ The source code for this tutorial can be found on [GitHub](https://github.com/gr
Read the GraphQL Java [documentation](https://www.graphql-java.com/documentation/getting-started).

### More Spring for GraphQL examples
See samples in the [1.0.x branch](https://github.com/spring-projects/spring-graphql/tree/1.0.x/samples), which will soon be [moved into](https://github.com/spring-projects/spring-graphql/issues/208) a separate repository.
See the [Spring for GraphQL documentation for more samples](https://docs.spring.io/spring-graphql/reference/samples.html).

### GitHub Discussions
We also use [GitHub Discussions](https://github.com/graphql-java/graphql-java/discussions) for any questions or problems.
Binary file removed static/img/docusaurus.png
Binary file not shown.
Binary file modified static/img/graphiQL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading