404 Während der Selbstbeobachtung in GraphQL mit dynamischer CodegenerierungJava

Java-Forum
Guest
 404 Während der Selbstbeobachtung in GraphQL mit dynamischer Codegenerierung

Post by Guest »

Ich versuche, während der Laufzeit ein GraphQL -Schema ohne statische Schema -Definitionen zu erstellen. Ich habe die folgenden Klassen < /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.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post