Problem
Hello friends,
I am in the process of converting my cinemanight API to be compatible with graphql. I have the problem when I try to generate the structure of the Extra type
, where you can see the example in the following link https://cinemanight.chrismichael.now.sh/api/v1/series/1
It shows me an error related to the Field \" extra \ "of type \" [Extra!]! \ "must have a selection of subfields. Did you mean \ "extra {...} \"?
According to the example of the endpoint route that I show you; Extra is of a list
type, so I defined it as[Extra]
, but apparently it should not be of that type.
Any help I would appreciate!
Error
{
"error": {
"errors": [
{
"message": "Field \"extra\" of type \"[Extra!]!\" must have a selection of subfields. Did you mean \"extra { ... }\"?",
"locations": [
{
"line": 10,
"column": 5
}
],
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Field \"extra\" of type \"[Extra!]!\" must have a selection of subfields. Did you mean \"extra { ... }\"?",
" at Object.Field (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\graphql\\validation\\rules\\ScalarLeafs.js:45:31)",
" at Object.enter (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\graphql\\language\\visitor.js:324:29)",
" at Object.enter (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\graphql\\language\\visitor.js:375:25)",
" at visit (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\graphql\\language\\visitor.js:242:26)",
" at Object.validate (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\graphql\\validation\\validate.js:73:24)",
" at validate (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:212:32)",
" at Object.<anonymous> (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:125:42)",
" at Generator.next (<anonymous>)",
" at fulfilled (C:\\Users\\c\\Desktop\\cinemanight-graphql\\node_modules\\apollo-server-core\\dist\\requestPipeline.js:5:58)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
}
}
]
}
}
const {gql} = require('apollo-server');
const typeDefs = gql `
extend type Query{
series(page: Int!): [Series!]!
}
type Series{
id: String!
title: String!
sinopsis: String!
poster: String!
rating: String!
year: String!
extra: [Extra!]!
}
type Extra{
channel: String!
first_air_date: String!
last_air_date: String!
total_seasons: String!
total_episodes: String
season_list: [SeasonList!]!
cast_members: CastMembers!
similar_series: [SimilarSeries!]!
}
type SeasonList{
season: Int
episodes: [String]
}
type SimilarSeries{
id: String!
poster: String!
}
type CastMembers{
creator: Creator!
members_list: [MembersList!]!
}
type MembersList{
members_info: [MembersInfo!]!
}
type MembersInfo{
characters: Characters!
}
type Characters{
real_name: String!
character: String!
}
type Creator{
name: String!
poster: String!
}
`;
const resolvers ={
Query:{
series: async(_source , {page} , { dataSources }) =>{
return dataSources.API.getAllSeries(page)
.then(doc =>{
return doc.series
});
}
}
}
module.exports = {
typeDefs,
resolvers
}