Skip to content
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

Java Records support #116

Open
MarcinLachowicz opened this issue Jan 25, 2022 · 2 comments
Open

Java Records support #116

MarcinLachowicz opened this issue Jan 25, 2022 · 2 comments

Comments

@MarcinLachowicz
Copy link

MarcinLachowicz commented Jan 25, 2022

Hello,
it looks like records are not supported:


public record TestRecord(String name) {
}
15:36:33.253 ERROR [main] o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [io/leangen/graphql/spqr/spring/autoconfigure/BaseAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is graphql.schema.validation.InvalidSchemaException: invalid schema:
"TestRecord" must define one or more fields.
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at com.test.Test.main(Test.java:14)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception; nested exception is graphql.schema.validation.InvalidSchemaException: invalid schema:
"TestRecord" must define one or more fields.
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 19 common frames omitted
Caused by: graphql.schema.validation.InvalidSchemaException: invalid schema:
"TestRecord" must define one or more fields.
	at graphql.schema.GraphQLSchema$Builder.buildImpl(GraphQLSchema.java:647)
	at graphql.schema.GraphQLSchema$Builder.build(GraphQLSchema.java:622)
	at io.leangen.graphql.GraphQLSchemaGenerator.generate(GraphQLSchemaGenerator.java:1036)
	at io.leangen.graphql.spqr.spring.autoconfigure.BaseAutoConfiguration.graphQLSchema(BaseAutoConfiguration.java:269)
	at io.leangen.graphql.spqr.spring.autoconfigure.BaseAutoConfiguration$$EnhancerBySpringCGLIB$$f5c843a6.CGLIB$graphQLSchema$4(<generated>)
	at io.leangen.graphql.spqr.spring.autoconfigure.BaseAutoConfiguration$$EnhancerBySpringCGLIB$$f5c843a6$$FastClassBySpringCGLIB$$f921aed4.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at io.leangen.graphql.spqr.spring.autoconfigure.BaseAutoConfiguration$$EnhancerBySpringCGLIB$$f5c843a6.graphQLSchema(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 20 common frames omitted

Process finished with exit code 1

@cgenrich
Copy link

Fixed in leangen/graphql-spqr#425, must be merged and used in this project.

@kaqqao
Copy link
Member

kaqqao commented Aug 9, 2023

Records are partially supported out of the box. When used as output types, records should work fine. As inputs, support is not yet there.

Make sure you're using the latest SPQR version.
Remember that you can always provide custom ResolverBuilder and/or InputFieldBuilder (or even a custom TypeMapper) to add support for any type.

Future versions will include full record type support. But, if you end up implementing it yourself, please so kind to contribute it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants