What should graphql schema definition for Page class looks like?
so I have this class in kotlin:
@Component
class UserResolver @Autowired
constructor(private val userService: UserService): GraphQLMutationResolver, GraphQLQueryResolver {
fun createUser(user: User): User {
userService.save(user)
return user
}
fun users(): Page<User> {
val pageable = QPageRequest(0, 10)
return userService.all(pageable)
}
}
I want the method users to return Page object, I am completely new to graphql. I tried something like this:
type Page {
number: Int
size: Int
numberOfElements: Int
content:
hasContent: Boolean
isFirst: Boolean
isLast: Boolean
hasNext: Boolean
hasPrevoius: Boolean
totalPages: Int
totalElements: Float
}
but my spring boot app is failing to start, I have no ideas what my schema definition for this class https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html should look like. Does anyone have an idea?
Edit: error is:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory
method 'schemaParser' threw exception; nested exception is
com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException:
Type
org.springframework.data.domain.Page<sk.matusko.wixit.common.dao.User
> cannot be mapped to a GraphQL type! Since GraphQL-Java deals
with erased types at runtime, only non-parameterized classes can
represent a GraphQL type. This allows for reverse-lookup by java
class in interfaces and union types.
kotlin spring-data graphql graphql-java
add a comment |
so I have this class in kotlin:
@Component
class UserResolver @Autowired
constructor(private val userService: UserService): GraphQLMutationResolver, GraphQLQueryResolver {
fun createUser(user: User): User {
userService.save(user)
return user
}
fun users(): Page<User> {
val pageable = QPageRequest(0, 10)
return userService.all(pageable)
}
}
I want the method users to return Page object, I am completely new to graphql. I tried something like this:
type Page {
number: Int
size: Int
numberOfElements: Int
content:
hasContent: Boolean
isFirst: Boolean
isLast: Boolean
hasNext: Boolean
hasPrevoius: Boolean
totalPages: Int
totalElements: Float
}
but my spring boot app is failing to start, I have no ideas what my schema definition for this class https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html should look like. Does anyone have an idea?
Edit: error is:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory
method 'schemaParser' threw exception; nested exception is
com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException:
Type
org.springframework.data.domain.Page<sk.matusko.wixit.common.dao.User
> cannot be mapped to a GraphQL type! Since GraphQL-Java deals
with erased types at runtime, only non-parameterized classes can
represent a GraphQL type. This allows for reverse-lookup by java
class in interfaces and union types.
kotlin spring-data graphql graphql-java
1
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25
add a comment |
so I have this class in kotlin:
@Component
class UserResolver @Autowired
constructor(private val userService: UserService): GraphQLMutationResolver, GraphQLQueryResolver {
fun createUser(user: User): User {
userService.save(user)
return user
}
fun users(): Page<User> {
val pageable = QPageRequest(0, 10)
return userService.all(pageable)
}
}
I want the method users to return Page object, I am completely new to graphql. I tried something like this:
type Page {
number: Int
size: Int
numberOfElements: Int
content:
hasContent: Boolean
isFirst: Boolean
isLast: Boolean
hasNext: Boolean
hasPrevoius: Boolean
totalPages: Int
totalElements: Float
}
but my spring boot app is failing to start, I have no ideas what my schema definition for this class https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html should look like. Does anyone have an idea?
Edit: error is:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory
method 'schemaParser' threw exception; nested exception is
com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException:
Type
org.springframework.data.domain.Page<sk.matusko.wixit.common.dao.User
> cannot be mapped to a GraphQL type! Since GraphQL-Java deals
with erased types at runtime, only non-parameterized classes can
represent a GraphQL type. This allows for reverse-lookup by java
class in interfaces and union types.
kotlin spring-data graphql graphql-java
so I have this class in kotlin:
@Component
class UserResolver @Autowired
constructor(private val userService: UserService): GraphQLMutationResolver, GraphQLQueryResolver {
fun createUser(user: User): User {
userService.save(user)
return user
}
fun users(): Page<User> {
val pageable = QPageRequest(0, 10)
return userService.all(pageable)
}
}
I want the method users to return Page object, I am completely new to graphql. I tried something like this:
type Page {
number: Int
size: Int
numberOfElements: Int
content:
hasContent: Boolean
isFirst: Boolean
isLast: Boolean
hasNext: Boolean
hasPrevoius: Boolean
totalPages: Int
totalElements: Float
}
but my spring boot app is failing to start, I have no ideas what my schema definition for this class https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html should look like. Does anyone have an idea?
Edit: error is:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.coxautodev.graphql.tools.SchemaParser]: Factory
method 'schemaParser' threw exception; nested exception is
com.coxautodev.graphql.tools.TypeClassMatcher$RawClassRequiredForGraphQLMappingException:
Type
org.springframework.data.domain.Page<sk.matusko.wixit.common.dao.User
> cannot be mapped to a GraphQL type! Since GraphQL-Java deals
with erased types at runtime, only non-parameterized classes can
represent a GraphQL type. This allows for reverse-lookup by java
class in interfaces and union types.
kotlin spring-data graphql graphql-java
kotlin spring-data graphql graphql-java
edited Dec 2 '18 at 21:42
TeeKea
3,22851832
3,22851832
asked Nov 25 '18 at 22:22
Matúš BartkoMatúš Bartko
1,4481931
1,4481931
1
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25
add a comment |
1
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25
1
1
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25
add a comment |
1 Answer
1
active
oldest
votes
The handling of generics has changed a bit with GraphQL Java Tools in the last few months. What version are you using? I just tried it with version 5.4.1 and it seemed to work, though with 5.2.4 it didn't. I wonder if the fix to this issue might be related.
In case it helps, here's the test stuff I used:
Firstly, I declared a class like this: class Page<T>(val number: Int, val size: Int)
Secondly, in the resolver I had fun users() = Page<User>(...)
Thirdly, in the GraphQL schema file I had this
type Page {
number: Int
size: Int!
}
type Query {
users: Page
}
The limitation with the above is that you have a single type in the GraphQL schema, simply called Page
. But presumably you want something specific about User
objects? Is this meant to be in the content
property in your example? If so, I think you need to declare a separate type in the GraphQL schema for every type that you might pass into the generic type parameter of Page
, e.g. UserPage
, CustomerPage
, etc. Then in the code each of those needs to be mapped to the correct Kotlin class, e.g. Page<User>
, Page<Customer>
. I don't know of a way to do that in code without having a concrete implementation of each of the generics (hopefully if it's possible someone else can explain how to do this). The GraphQL types names are married up to the Kotlin class names by default if they have the same name, or using an explicitly provided mapping when building the Schema
using SchemaParser.newParser().dictionary(...
So if you're happy creating concrete subclasses of the generic class for each type you supply to it, you can do something like this:
open class Page<T>(val number: Int, val size: Int, val content: List<T>)
class UserPage(number: Int, size: Int, content: List<User>): Page<User>(number, size, content)
fun users(): UserPage {...
And in the GraphQL schema you'd have this:
type UserPage {
number: Int!
size: Int!
content: [User]!
}
type Query {
users: UserPage
}
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472601%2fwhat-should-graphql-schema-definition-for-page-class-looks-like%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The handling of generics has changed a bit with GraphQL Java Tools in the last few months. What version are you using? I just tried it with version 5.4.1 and it seemed to work, though with 5.2.4 it didn't. I wonder if the fix to this issue might be related.
In case it helps, here's the test stuff I used:
Firstly, I declared a class like this: class Page<T>(val number: Int, val size: Int)
Secondly, in the resolver I had fun users() = Page<User>(...)
Thirdly, in the GraphQL schema file I had this
type Page {
number: Int
size: Int!
}
type Query {
users: Page
}
The limitation with the above is that you have a single type in the GraphQL schema, simply called Page
. But presumably you want something specific about User
objects? Is this meant to be in the content
property in your example? If so, I think you need to declare a separate type in the GraphQL schema for every type that you might pass into the generic type parameter of Page
, e.g. UserPage
, CustomerPage
, etc. Then in the code each of those needs to be mapped to the correct Kotlin class, e.g. Page<User>
, Page<Customer>
. I don't know of a way to do that in code without having a concrete implementation of each of the generics (hopefully if it's possible someone else can explain how to do this). The GraphQL types names are married up to the Kotlin class names by default if they have the same name, or using an explicitly provided mapping when building the Schema
using SchemaParser.newParser().dictionary(...
So if you're happy creating concrete subclasses of the generic class for each type you supply to it, you can do something like this:
open class Page<T>(val number: Int, val size: Int, val content: List<T>)
class UserPage(number: Int, size: Int, content: List<User>): Page<User>(number, size, content)
fun users(): UserPage {...
And in the GraphQL schema you'd have this:
type UserPage {
number: Int!
size: Int!
content: [User]!
}
type Query {
users: UserPage
}
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
add a comment |
The handling of generics has changed a bit with GraphQL Java Tools in the last few months. What version are you using? I just tried it with version 5.4.1 and it seemed to work, though with 5.2.4 it didn't. I wonder if the fix to this issue might be related.
In case it helps, here's the test stuff I used:
Firstly, I declared a class like this: class Page<T>(val number: Int, val size: Int)
Secondly, in the resolver I had fun users() = Page<User>(...)
Thirdly, in the GraphQL schema file I had this
type Page {
number: Int
size: Int!
}
type Query {
users: Page
}
The limitation with the above is that you have a single type in the GraphQL schema, simply called Page
. But presumably you want something specific about User
objects? Is this meant to be in the content
property in your example? If so, I think you need to declare a separate type in the GraphQL schema for every type that you might pass into the generic type parameter of Page
, e.g. UserPage
, CustomerPage
, etc. Then in the code each of those needs to be mapped to the correct Kotlin class, e.g. Page<User>
, Page<Customer>
. I don't know of a way to do that in code without having a concrete implementation of each of the generics (hopefully if it's possible someone else can explain how to do this). The GraphQL types names are married up to the Kotlin class names by default if they have the same name, or using an explicitly provided mapping when building the Schema
using SchemaParser.newParser().dictionary(...
So if you're happy creating concrete subclasses of the generic class for each type you supply to it, you can do something like this:
open class Page<T>(val number: Int, val size: Int, val content: List<T>)
class UserPage(number: Int, size: Int, content: List<User>): Page<User>(number, size, content)
fun users(): UserPage {...
And in the GraphQL schema you'd have this:
type UserPage {
number: Int!
size: Int!
content: [User]!
}
type Query {
users: UserPage
}
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
add a comment |
The handling of generics has changed a bit with GraphQL Java Tools in the last few months. What version are you using? I just tried it with version 5.4.1 and it seemed to work, though with 5.2.4 it didn't. I wonder if the fix to this issue might be related.
In case it helps, here's the test stuff I used:
Firstly, I declared a class like this: class Page<T>(val number: Int, val size: Int)
Secondly, in the resolver I had fun users() = Page<User>(...)
Thirdly, in the GraphQL schema file I had this
type Page {
number: Int
size: Int!
}
type Query {
users: Page
}
The limitation with the above is that you have a single type in the GraphQL schema, simply called Page
. But presumably you want something specific about User
objects? Is this meant to be in the content
property in your example? If so, I think you need to declare a separate type in the GraphQL schema for every type that you might pass into the generic type parameter of Page
, e.g. UserPage
, CustomerPage
, etc. Then in the code each of those needs to be mapped to the correct Kotlin class, e.g. Page<User>
, Page<Customer>
. I don't know of a way to do that in code without having a concrete implementation of each of the generics (hopefully if it's possible someone else can explain how to do this). The GraphQL types names are married up to the Kotlin class names by default if they have the same name, or using an explicitly provided mapping when building the Schema
using SchemaParser.newParser().dictionary(...
So if you're happy creating concrete subclasses of the generic class for each type you supply to it, you can do something like this:
open class Page<T>(val number: Int, val size: Int, val content: List<T>)
class UserPage(number: Int, size: Int, content: List<User>): Page<User>(number, size, content)
fun users(): UserPage {...
And in the GraphQL schema you'd have this:
type UserPage {
number: Int!
size: Int!
content: [User]!
}
type Query {
users: UserPage
}
The handling of generics has changed a bit with GraphQL Java Tools in the last few months. What version are you using? I just tried it with version 5.4.1 and it seemed to work, though with 5.2.4 it didn't. I wonder if the fix to this issue might be related.
In case it helps, here's the test stuff I used:
Firstly, I declared a class like this: class Page<T>(val number: Int, val size: Int)
Secondly, in the resolver I had fun users() = Page<User>(...)
Thirdly, in the GraphQL schema file I had this
type Page {
number: Int
size: Int!
}
type Query {
users: Page
}
The limitation with the above is that you have a single type in the GraphQL schema, simply called Page
. But presumably you want something specific about User
objects? Is this meant to be in the content
property in your example? If so, I think you need to declare a separate type in the GraphQL schema for every type that you might pass into the generic type parameter of Page
, e.g. UserPage
, CustomerPage
, etc. Then in the code each of those needs to be mapped to the correct Kotlin class, e.g. Page<User>
, Page<Customer>
. I don't know of a way to do that in code without having a concrete implementation of each of the generics (hopefully if it's possible someone else can explain how to do this). The GraphQL types names are married up to the Kotlin class names by default if they have the same name, or using an explicitly provided mapping when building the Schema
using SchemaParser.newParser().dictionary(...
So if you're happy creating concrete subclasses of the generic class for each type you supply to it, you can do something like this:
open class Page<T>(val number: Int, val size: Int, val content: List<T>)
class UserPage(number: Int, size: Int, content: List<User>): Page<User>(number, size, content)
fun users(): UserPage {...
And in the GraphQL schema you'd have this:
type UserPage {
number: Int!
size: Int!
content: [User]!
}
type Query {
users: UserPage
}
edited Dec 6 '18 at 15:07
answered Dec 5 '18 at 15:02
Yoni GibbsYoni Gibbs
1,368113
1,368113
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
add a comment |
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
yes thanks, upgrade graphql java tools to 5.4.1 and kotlin to 1.3.0 was necessary
– Matúš Bartko
Dec 8 '18 at 23:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472601%2fwhat-should-graphql-schema-definition-for-page-class-looks-like%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you share the error output from the logs?
– pipo_dev
Nov 30 '18 at 23:34
@pipo_dev edited
– Matúš Bartko
Dec 2 '18 at 21:25