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

Warning log: Schema type was defined but can never be accessed, and can be safely deleted: PageInfo #219

Closed
jjjimenez100 opened this issue Jan 10, 2019 · 6 comments

Comments

@jjjimenez100
Copy link

jjjimenez100 commented Jan 10, 2019

I can seem to access /graphql and /graphiql endpoints. However, it seems like the schema is not being read, as going to the /schema.json endpoint returns me a bunch of null json string.

Spring Boot version: 2.1.1 RELEASE
Graphql boot starter: 5.3.1
Graphql java tools: 5.4.1

What could have I done wrong?

Schema file (at resources folder) (name is type.graphqls)

type Query {
    dogs: [Dog]
    persons: [Person]
    person(id: Int!): Person
    dog(id: Int!): Dog
}

type Dog {
    id: Int
    name: String
    breed: String
}

type Person {
    id: Int
    name: String
    age: Int
}

Dog class

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Data
@Entity
@NoArgsConstructor
public class Dog {
    private @Id @GeneratedValue int id;
    private String name;
    private String breed;
}

Person model

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Data
@Entity
@NoArgsConstructor
public class Person {
    private @Id @GeneratedValue int id;
    private String name;
    private int age;
}

Query Resolver

import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import io.toro.ojtbe.jimenez.Graphify.models.Dog;
import io.toro.ojtbe.jimenez.Graphify.models.Person;
import io.toro.ojtbe.jimenez.Graphify.models.repositories.DogRepository;
import io.toro.ojtbe.jimenez.Graphify.models.repositories.PersonRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class QueryResolver implements GraphQLQueryResolver {
    private DogRepository dogRepository;
    private PersonRepository personRepository;

    public List<Dog> dogs(){
        return dogRepository.findAll();
    }

    public List<Person> persons(){
        return personRepository.findAll();
    }

    public Dog dog(Dog dog){
        return dogRepository.findById(dog.getId()).get();
    }

    public Person person(Person person){
        return personRepository.findById(person.getId()).get();
    }
}

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId></groupId>
	<artifactId>Graphify</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name></name>
	<description></description>

	<properties>
		<java.version>1.8</java.version>
		<kotlin.version>1.3.10</kotlin.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>com.graphql-java-kickstart</groupId>
			<artifactId>graphql-spring-boot-starter</artifactId>
			<version>5.3.1</version>
		</dependency>
		<dependency>
			<groupId>com.graphql-java-kickstart</groupId>
			<artifactId>graphql-java-tools</artifactId>
			<version>5.4.1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>com.graphql-java-kickstart</groupId>
			<artifactId>graphiql-spring-boot-starter</artifactId>
			<version>5.3.1</version>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
@jjjimenez100
Copy link
Author

Tried adding @Autowired annotation on repository instances at the QueryResolver class.

Now I am able to query with graphiql, and it returns the result perfectly. However, requesting directly to the /graphql endpoint still won't give any response and logs me with this:

Bad GET request: path was not "/schema.json" or no query variable named "query" given

and the same

Warning log: Schema type was defined but can never be accessed, and can be safely deleted: PageInfo

is still being logged

@oliemansm
Copy link
Member

The methods dog and person in your QueryResolver should have the id as parameter instead of the object.

Based on the error message you get when you execute the query directly and the fact that GraphiQL is working properly it sounds like you're not sending the GraphQL request in the right way. Since you have GraphiQL running ok now the easiest way would be to take a look at the dev console while executing a request and learn from that example how the request should be sent.

@jjjimenez100
Copy link
Author

jjjimenez100 commented Jan 10, 2019

My bad on your first point and second point. I was actually referencing majority of my code with a tutorial online, until I saw the getId methods returning me an error saying it should be converted to a numeric type. (Since it's id, lol.) I was also able to run a proper query with a curl request, since I've been doing it previously with Postman.

I would be more than happy to close the issue, however, this message is still being logged:

Warning log: Schema type was defined but can never be accessed, and can be safely deleted: PageInfo

even though the endpoint works fine. Any ideas? Or should I just disregard this?

Thank you.

@oliemansm
Copy link
Member

That's a known issue you can disregard, see #215.

@jjjimenez100
Copy link
Author

Alright, thanks! Closing this issue now.

@vijay26051991
Copy link

Bad GET request: path was not "/schema.json" I see this.. How to resolve it

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