Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

spring-graphql

/spring-graphql

Wspiera budowę API GraphQL w Spring for GraphQL: zapytania, mutacje, subskrypcje, @BatchMapping, DataLoader i bezpieczeństwo.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wspiera budowę API GraphQL w Spring for GraphQL: zapytania, mutacje, subskrypcje, @BatchMapping, DataLoader i bezpieczeństwo.

Wyzwalacze z opisu

spring graphql@QueryMapping@MutationMapping@SubscriptionMapping@BatchMappingGraphQL Spring BootN+1 GraphQL
Oryginalny opis (EN)

Spring for GraphQL - building GraphQL APIs with Spring Boot. Covers queries, mutations, subscriptions, @BatchMapping, DataLoader, and security. USE WHEN: user mentions "spring graphql", "@QueryMapping", "@MutationMapping", "@SubscriptionMapping", "@BatchMapping", "GraphQL Spring Boot", "N+1 GraphQL" DO NOT USE FOR: REST APIs - use standard Spring MVC, standalone GraphQL - use `graphql-java` skill

Jak działa

  1. Dependencies
  2. Configuration
  3. Schema Definition
  4. Query Controller
  5. Mutation Controller
  6. BatchMapping (Solve N+1)
  7. Input Validation
  8. Error Handling
  9. Security
  10. When NOT to Use This Skill
Sekcje z nagłówków SKILL.md, w oryginale · 226 linii, 630 słów
Podgląd SKILL.md
---
name: spring-graphql
description: |
  Spring for GraphQL - building GraphQL APIs with Spring Boot.
  Covers queries, mutations, subscriptions, @BatchMapping, DataLoader, and security.

  USE WHEN: user mentions "spring graphql", "@QueryMapping", "@MutationMapping",
  "@SubscriptionMapping", "@BatchMapping", "GraphQL Spring Boot", "N+1 GraphQL"

  DO NOT USE FOR: REST APIs - use standard Spring MVC,
  standalone GraphQL - use `graphql-java` skill
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Spring for GraphQL - Quick Reference

> **Full Reference**: See [advanced.md](advanced.md) for DataLoader configuration, custom scalars, pagination implementation, GraphQL testing patterns, and subscription controllers.

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `spring-graphql` for comprehensive documentation.

## Dependencies

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-graphql</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
```

## Configuration

```yaml
spring:
  graphql:
    graphiql:
      enabled: true
      path: /graphiql
    schema:
      locations: classpath:graphql/**/
    path: /graphql
    websocket:
      path: /graphql
```

## Schema Definition

```graphql
type Query {
    bookById(id: ID!): Book
    allBooks: [Book!]!
}

type Mutation {
    createBook(input: CreateBookInput!): Book!
}

type Book {
    id: ID!
    title: String!
    author: Author!
}

input CreateBookInput {
    title: String!
    authorId: ID!
}
```

## Query Controller

```java
@Controller
public class BookController {

    @QueryMapping
    public Book bookById(@Argument String id) {
        return bookRepository.findById(id).orElse(null);
    }

    @QueryMapping
    public List<Book> allBooks() {
        return bookRepository.findAll();
    }

    @SchemaMapping(typeName = "Book", field = "author")
    public Author author(Book book) {
        return authorRepository.findById(book.getAuthorId()).orElse(null);
    }
}
```

## Mutation Controller

```java
@Controller
public class BookMutationController {

    @MutationMapping
    public Book createBook(@Argument CreateBookInput input) {
        return bookService.create(input);
    }
}
```

## BatchMapping (Solve N+1)

```java
@Controller
public class OptimizedBookController {

    @BatchMapping
    public Map<Book, Author> author(List<Book> books) {
        List<String> authorIds = books.stream()
            .map(Book::getAuthorId)
            .distinct()
            .toList();

        Map<String, Author> authorsById = authorRepository.findAllById(authorIds)
            .stream()
            .collect(Collectors.toMap(Author::getId, a -> a));

        return books.stream()
            .collect(Collectors.toMap(
                book -> book,
                book -> authorsById.get(book.getAuthorId())
            ));
    }
}
```

## Input Validation

```java
@MutationMapping
public Book createBook(@Argument @Valid CreateBookInput input) {
    return bookService.create(input);
}

public record CreateBookInput(
    @NotBlank @Size(min = 1, max = 200) String title,
    @NotNull String authorId
) {}
```

## Error Handling

```java
@Component
public class CustomExceptionResolver extends DataFetcherExceptionResolverAdapter {

    @Override
    protected GraphQLError resolveToSingleError(Throwable ex, DataFetchingEnvironment env) {
        if (ex instanceof BookNotFoundException) {
            return GraphqlErrorBuilder.newError(env)
                .errorType(ErrorType.NOT_FOUND)
                .message(ex.getMessage())
                .build();
        }
        return null;
    }
}
```

## Security

```java
@Controller
public class SecuredBookController {

    @QueryMapping
    @PreAuthorize("hasRole('USER')")
    public List<Book> allBooks() {
        return bookRepository.findAll();
    }

    @MutationMapping
    @PreAuthorize("hasRole('ADMIN')")
    public Book createBook(@Argument CreateBookInput input) {
        return bookService.create(input);
    }
}
```

## When NOT to Use This Skill

- **REST APIs** - Use standard Spring MVC controllers
- **Standalone GraphQL** - Use graphql-java directly
- **Simple CRUD** - May be overkill, consider REST
- **File uploads** - GraphQL isn't optimized for large binary data

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| No @BatchMapping | N+1 queries on nested fields | Use @BatchMapping or DataLoader |
| Unbounded lists | Memory exhaustion | Implement pagination |
| Exposing entities | Schema tightly coupled to DB | Use DTOs/projections |
| No error handling | Stack traces exposed | Custom ExceptionResolver |
| GraphiQL in prod | Security risk | Disable in production |

## Quick Troubleshooting

| Problem | Diagnostic | Fix |
|---------|------------|-----|
| N+1 queries | Check SQL logs | Add @BatchMapping |
| Field not resolved | Check method name | Verify @SchemaMapping matches schema |
| Subscription not working | Check WebSocket config | Enable WebSocket support |
| Validation not applied | Check @Valid | Add @Validated to controller |
| Auth not working | Check security config | Add @PreAuthorize annotations |

## Best Practices

| Do | Don't |
|----|-------|
| Use @BatchMapping for N+1 | Fetch nested data individually |
| Define clear schema contracts | Over-expose internal models |
| Implement pagination | Return unbounded lists |
| Use input types for mutations | Use many scalar arguments |
| Add proper error handling | Expose stack traces |

## Production Checklist

- [ ] Schema well defined
- [ ] N+1 solved with BatchMapping
- [ ] Input validation enabled
- [ ] Error handling configured
- [ ] Security annotations applied
- [ ] Pagination implemented
- [ ] GraphiQL disabled in prod
- [ ] Query complexity limits
- [ ] Introspection controlled

## Reference Documentation

- [Spring for GraphQL Reference](https://docs.spring.io/spring-graphql/reference/)
Pliki w paczce (2)
  • SKILL.md 6 KB
  • advanced.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie spring-graphql.

Migawka bazy z 28.10.2026 · wersja paczki adb63617303d (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100graphql
    Pomaga projektować API GraphQL: schemat, zapytania, mutacje i resolvery, a także uwierzytelnianie, paginację, DataLoader i Apollo Server.
  • 100graphql
    Wspiera tworzenie API GraphQL: projekt schematu, architekturę resolverów, wykrywanie N+1 z DataLoader, subskrypcje, federację i poprawę wydajności.
  • 100spring-boot-expert
    Wspiera pracę z Spring Boot, Spring Framework, API REST i mikroserwisami w Javie.
  • 100spring-boot
    Wspiera tworzenie w Spring Boot 4 REST API, warstwy JPA, bezpieczeństwa, testów i usług chmurowych.
  • 100graphql
    Pomaga budować i konsumować API GraphQL: serwer, schematy, resolvery, subskrypcje, uwierzytelnianie, DataLoader, paginacja, przesyłanie plików i migracja z REST przy użyciu Apollo.
  • 100graphql-expert
    Wspiera tworzenie API GraphQL na poziomie eksperckim: projekt schematu, resolvery, subskrypcje, Apollo Server 4 i DataLoader przeciw problemowi N+1.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.