Reputation: 13
I'm trying to implement a GraphQL server in my Spring Boot application. I'm encountering a problem where the field names in my GraphQL schema do not match the field names in my Java entities. Here are the details:
schema.graphqls
type Book {
book_id: ID!
title: String!
}
Java Entity
@Table(name = "book")
public class Book {
@Id
@Column(name="book_id")
private BigDecimal bookID;
private String title;
....
// Getters and setters
}
When querying book_id in GraphQL, I get the following error because it doesn’t seem to map to bookID in the Java entity. I tried renaming the field in my entity to book_id, but that’s not a feasible long-term solution.
> The field at path '/getAllBooks[0]/book_id' was declared as a non null
> type, but the code involved in retrieving data has wrongly returned a
> null value. The graphql specification requires that the parent field
> be set to null, or if that is non nullable that it bubble up null to
> its parent and so on. The non-nullable type is 'ID' within parent type
> 'Book
I cant use GraphQLField from graphql-java-tools as its not available in local nexus.
Is there any way to handle naming discrepancy ?
Upvotes: 0
Views: 42