配置文件
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.example.demo.resolver.Mutation;
import com.example.demo.resolver.Query;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import static com.coxautodev.graphql.tools.SchemaParser.newParser;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private static Query query;
@Autowired
private static Mutation mutation;
@Bean
public BCryptPasswordEncoder passwordEncoder() {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder;
}
@Autowired
public GraphQL graphQL() {
return GraphQL.newGraphQL(graphQLSchema())
.build();
}
public static GraphQLSchema graphQLSchema(){
return newParser()
.file("schema.graphqls")
.resolvers(query,mutation)
.build()
.makeExecutableSchema();
}
}
Run Code Online (Sandbox Code Playgroud)
图式
type User {
uid: Long!
name: …Run Code Online (Sandbox Code Playgroud)