404 во время самоанализа в GraphQL с динамическим генерацией кодаJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 404 во время самоанализа в GraphQL с динамическим генерацией кода

Сообщение Anonymous »

Я пытаюсь создать схему GraphQL во время выполнения без каких -либо статических определений схемы. У меня есть следующие классы < /p>
@Component
public class GraphQLProvider {

private GraphQL graphQL;

private final ConnectionManager connectionManager;

public GraphQLProvider(ConnectionManager connectionManager) {this.connectionManager = connectionManager;}

@PostConstruct
public void init() {
GraphQLSchema schema = buildSchema();

System.out.println( new SchemaPrinter().print( schema ) );

this.graphQL = GraphQL.newGraphQL( schema ).build();
}

public GraphQL getGraphQL() {
return graphQL;
}

private GraphQLSchema buildSchema() {
GraphQLObjectType queryType = GraphQLObjectType.newObject().name( "Query" )
.field( field -> field
.name( "hello" )
.type( Scalars.GraphQLString )
.dataFetcher( environment -> "world" ) )
.build();

return GraphQLSchema.newSchema().query( queryType ).build();
}

}
< /code>
@Configuration
public class GraphQLConfig {

@Bean
@Primary
public GraphQlSource graphQlSource(GraphQLProvider graphQLProvider) {
GraphQLSchema schema = graphQLProvider.getGraphQL().getGraphQLSchema();
return GraphQlSource.builder( schema ).build();
}
}
< /code>
The schema printed by schemaprinter is expected and its correct.
I experience 404 when I try to query with this setup in postman but if i run with predefined graphql schemas without the dynamic generation i get the result as expected.
The error
2025-02-14 09:51:41,945+0530 DEBUG [org.springframework.security.web.FilterChainProxy] (http-nio-9900-exec-1) [-] [] Secured POST /graphql
2025-02-14 09:51:41,950+0530 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-nio-9900-exec-1) [-] [] POST "/graphql", parameters={}
2025-02-14 09:51:41,953+0530 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (http-nio-9900-exec-1) [-] [] Mapped to ResourceHttpRequestHandler [classpath [public/], classpath [static/]]
2025-02-14 09:51:41,956+0530 DEBUG [org.springframework.web.servlet.resource.ResourceHttpRequestHandler] (http-nio-9900-exec-1) [-] [] Resource not found
2025-02-14 09:51:41,958+0530 DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (http-nio-9900-exec-1) [-] [] Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource graphql.]
2025-02-14 09:51:41,959+0530 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-nio-9900-exec-1) [-] [] Completed 404 NOT_FOUND
2025-02-14 09:51:41,973+0530 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-nio-9900-exec-1) [-] [] "ERROR" dispatch for POST "/error", parameters={}
2025-02-14 09:51:41,995+0530 DEBUG [org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor] (http-nio-9900-exec-1) [-] [] Using 'application/json', given [application/json, text/plain, */*] and supported [application/json, application/*+json, application/x-jackson-smile, application/cbor]
2025-02-14 09:51:41,997+0530 DEBUG [org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor] (http-nio-9900-exec-1) [-] [] Writing [{timestamp=Fri Feb 14 04:21:41 GMT 2025, status=404, error=Not Found, path=/graphql}]
2025-02-14 09:51:42,010+0530 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-nio-9900-exec-1) [-] [] Exiting from "ERROR" dispatch, status 404
< /code>
I don't want to any static files in my resources rather to be initialized in runtime.

Подробнее здесь: https://stackoverflow.com/questions/794 ... generation
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»