API의 쿼리 언어로 서버로부터 클라이언트가 원하는 데이터를 요청할 수 있는 문법을 제공한다.
type Location {
id: ID!
name: String!
address: String!
}
type Query {
findAllLocations: [Location]!
}
type Mutation {
newLocation(name: String!, address: String) : Location!
deleteLocation(id:ID!) : Boolean
updateLocationName(newName: String!, id:ID!) : Location!
}
@Component
public class Query implements GraphQLQueryResolver {
private final DogRepository dogRepository;
public Query(DogRepository dogRepository){
this.dogRepository = dogRepository;
}
public Iterable<Dog> findAllDogs(){
return dogRepository.findAll();
}
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password(encoder().encode("password"))
.roles("USER");
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
}