-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation with advice on how to achieve schema namespacing #863
Comments
As far as I understand, in Spring for GraphQL you should define your schema like this:
And then, in your Controller:
|
Stacked into one file, it is very difficult to maintain. Is it possible to support sub-modules Query and Mutation? |
Sorry for the delayed response. I had a look into this and I'll share my findings here. First I think that the suggested approach with Here's, what's missing is the actual type Query {
music: MusicQueries
users: UserQueries
}
type MusicQueries {
album(id: ID!): Album
searchForArtist(name: String!): [Artist]
}
type Album {
id: ID!
title: String!
}
type Artist {
id: ID!
name: String!
}
type UserQueries {
user(login: String): User
}
type User {
id: ID!
login: String!
}
package io.spring.sample.graphqlnamespace;
import java.util.List;
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
@SchemaMapping(typeName="MusicQueries")
public class MusicController {
@QueryMapping
public MusicQueries music() {
return new MusicQueries();
}
@SchemaMapping
public Album album(@Argument String id) {
return new Album(id, "Spring GraphQL");
}
@SchemaMapping
public List<Artist> searchForArtist(@Argument String name) {
return List.of(new Artist("100", "the Spring team"));
}
public record MusicQueries() {
}
public record Album(String id, String title) {
}
public record Artist(String id, String name) {
}
}
I don't think additional support is needed in Spring for GraphQL right now. We could turn this into a documentation issue and mention this pattern in the reference docs. @can-axelspringer would this work for you? |
The @Bean
public GraphQlSourceBuilderCustomizer customizer() {
List<String> queryWrappers = List.of("users", ... );
List<String> mutationWrappers = List.of("users", ... );
return sourceBuilder -> sourceBuilder.configureRuntimeWiring(wiringBuilder -> {
queryWrappers.forEach(field -> wiringBuilder.type("Query",
builder -> builder.dataFetcher(field, env -> Collections.emptyMap())));
mutationWrappers.forEach(field -> wiringBuilder.type("Mutation",
builder -> builder.dataFetcher(field, env -> Collections.emptyMap())));
});
} There isn't much we can do to make this easier, and it seems pretty straight forward in any case. |
Thank you very much for the help and support. I was able to reproduce proper namespacing setup using given examples. @bclozel and @rstoyanchev Thank you all again. |
Hello,
I hope this is the right place to ask this question. I could not find anything on the internet that could provide me with an answer.
Is it possible to define schemas like following:
When I attempt to do it like that. I can't make annotated controller model work.
The text was updated successfully, but these errors were encountered: