{"action":"closed","issue":{"url":"https://api.github.com/repos/apollographql/graphql-tools/issues/889","repository_url":"https://api.github.com/repos/apollographql/graphql-tools","labels_url":"https://api.github.com/repos/apollographql/graphql-tools/issues/889/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/graphql-tools/issues/889/comments","events_url":"https://api.github.com/repos/apollographql/graphql-tools/issues/889/events","html_url":"https://github.com/apollographql/graphql-tools/issues/889","id":341172014,"node_id":"MDU6SXNzdWUzNDExNzIwMTQ=","number":889,"title":"Schema Delegation on Schema Stitching is not working if the Parent return type is a list of Objects","user":{"login":"AdelBachene","id":12539262,"node_id":"MDQ6VXNlcjEyNTM5MjYy","avatar_url":"https://avatars0.githubusercontent.com/u/12539262?v=4","gravatar_id":"","url":"https://api.github.com/users/AdelBachene","html_url":"https://github.com/AdelBachene","followers_url":"https://api.github.com/users/AdelBachene/followers","following_url":"https://api.github.com/users/AdelBachene/following{/other_user}","gists_url":"https://api.github.com/users/AdelBachene/gists{/gist_id}","starred_url":"https://api.github.com/users/AdelBachene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdelBachene/subscriptions","organizations_url":"https://api.github.com/users/AdelBachene/orgs","repos_url":"https://api.github.com/users/AdelBachene/repos","events_url":"https://api.github.com/users/AdelBachene/events{/privacy}","received_events_url":"https://api.github.com/users/AdelBachene/received_events","type":"User","site_admin":false},"labels":[{"id":854170496,"node_id":"MDU6TGFiZWw4NTQxNzA0OTY=","url":"https://api.github.com/repos/apollographql/graphql-tools/labels/blocking","name":"blocking","color":"b60205","default":false},{"id":345415806,"node_id":"MDU6TGFiZWwzNDU0MTU4MDY=","url":"https://api.github.com/repos/apollographql/graphql-tools/labels/bug","name":"bug","color":"fc2929","default":true},{"id":854172166,"node_id":"MDU6TGFiZWw4NTQxNzIxNjY=","url":"https://api.github.com/repos/apollographql/graphql-tools/labels/has-reproduction","name":"has-reproduction","color":"42f44e","default":false},{"id":943550750,"node_id":"MDU6TGFiZWw5NDM1NTA3NTA=","url":"https://api.github.com/repos/apollographql/graphql-tools/labels/schema-stitching","name":"schema-stitching","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-13T22:01:26Z","updated_at":"2018-07-17T21:46:13Z","closed_at":"2018-07-17T21:46:13Z","author_association":"NONE","body":"/label bug\r\n/label schema-stitching\r\n- [x] has-reproduction\r\n- [ ] feature\r\n- [ ] docs\r\n- [x] blocking\r\n- [ ] good first issue\r\n\r\nPublication Type is defined as:\r\n\r\n>const PublicationType = new GraphQLObjectType({\r\n          name: 'Publication',\r\n          description: 'Publication Type',\r\n          fields: () => ({\r\n              id: {\r\n                  type: GraphQLID\r\n              },\r\n              callToAction: {\r\n                  type: CallToActionType\r\n              },\r\n              userId: {\r\n                  type: GraphQLID\r\n              },\r\n              groupId: {\r\n                  type: GraphQLID\r\n              },\r\n              instruction: {\r\n                  type: InstructionType\r\n              },\r\n              customizedTitle: {\r\n                  type: GraphQLString\r\n              },\r\n              content: {\r\n                  type: GraphQLString\r\n              },\r\n              activityType: {\r\n                  type: ActivityType\r\n              },\r\n              creationTool: {\r\n                  type: CreationTool\r\n              },\r\n              gift: {\r\n                  type: GiftType\r\n              },\r\n              imageId: {\r\n                  type: GraphQLInt\r\n              },\r\n              thumbnailId: {\r\n                  type: GraphQLInt\r\n              },\r\n              createdAt: {\r\n                  type: GraphQLInt\r\n              },\r\n              updatedAt: {\r\n                  type: GraphQLInt\r\n              }\r\n          })\r\n      });\r\n\r\nMedia Type is defined as : \r\n>const MediaType = new GraphQLObjectType({\r\n          name: 'Media',\r\n          description: 'Media Object',\r\n          fields: () => ({\r\n              id: {\r\n                  type: GraphQLInt\r\n              },\r\n              resource: {\r\n                  type: GraphQLString\r\n              },\r\n              metadata: {\r\n                  type: MetadataType\r\n              },\r\n              discr: {\r\n                  type: GraphQLString\r\n              }\r\n          })\r\n      });\r\n\r\nwhere MetadataType is an onther type defined in the code.\r\n\r\nthe 2 queries are defined as:\r\n\r\n>this._schema = new GraphQLObjectType({\r\n                  name: 'Query',\r\n                  description: 'Wall Query',\r\n                  fields: () => ({\r\n                      getGroupPublications: {\r\n                          type: new GraphQLList(PublicationType),\r\n                          args: {\r\n                              groupId: {type: new GraphQLNonNull(GraphQLInt)},\r\n                              from: {type: new GraphQLNonNull(GraphQLInt)},\r\n                              to: {type: new GraphQLNonNull(GraphQLInt)},\r\n                          },\r\n                          resolve: (root, args, context) => PublicationResolver.groupPublications(context)\r\n                      }\r\n                  }),\r\n              });\r\n\r\nAnd\r\n>      this._schema = new GraphQLObjectType({\r\n                  name: 'Query',\r\n                  description: 'Media Query',\r\n                  fields: () => ({\r\n                      getMedia: {\r\n                          type: MediaType,\r\n                          args: {\r\n                              mediaId: {type: new GraphQLNonNull(GraphQLInt)}\r\n                          },\r\n                          resolve: (root, args, context) => MediaResolver.mediaLoader(context).load(args.mediaId)\r\n                      }\r\n                  }),\r\n              });\r\n\r\n\r\nthen DB stitching is defined as: \r\n\r\n`import {mergeSchemas} from 'graphql-tools';\r\n    // other imports ...\r\n\r\n    class Services {\r\n\r\n        private static _instance: Services;\r\n        private _wall: PublicationService;\r\n        private _media: MediaService;\r\n\r\n        private constructor() {\r\n            this._media = new MediaService();\r\n            this._wall = new PublicationService();\r\n        }\r\n\r\n        public static Instance() {\r\n            return this._instance || (this._instance = new this())\r\n        }\r\n\r\n        public MainSchema = async () => Promise.all([this._publication.schema, this._media.schema])\r\n                .then(args => {\r\n                    const publicationSchema = args[0];\r\n                    const mediaSchema = args[1];\r\n\r\n                    const linkSchemaDefs = `\r\n                                    extend type Publication {\r\n                                        image: Media\r\n                                        thumbnail: Media\r\n                                    }`;\r\n\r\n                    return mergeSchemas({\r\n                        schemas: [publicationSchema, mediaSchema, linkSchemaDefs],\r\n                        resolvers: \r\n                            {\r\n                                Publication: {\r\n                                    image: {\r\n                                        fragment: `... on Publication { imageId }`,\r\n                                        resolve(parent, args, context, info) {\r\n                                            let mediaId = (parent.imageId === parseInt(parent.imageId, 10)) ? parent.imageId : 0;\r\n                                            return info.mergeInfo.delegateToSchema({\r\n                                                schema: mediaSchema,\r\n                                                operation: 'query',\r\n                                                fieldName: 'getMedia',\r\n                                                args: {\r\n                                                    mediaId: mediaId,\r\n                                                },\r\n                                                context,\r\n                                                info\r\n                                            })\r\n                                        }\r\n                                    },\r\n                                    thumbnail: {\r\n                                        fragment: 'fragment PublicationThumbnailFragment on Publication { thumbnailId }',\r\n                                        resolve(parent, args, context, info) {\r\n                                            let mediaId = (parent.thumbnailId === parseInt(parent.thumbnailId, 10)) ? parent.thumbnailId : 0;\r\n                                            return info.mergeInfo.delegateToSchema({\r\n                                                schema: mediaSchema,\r\n                                                operation: 'query',\r\n                                                fieldName: 'getMedia',\r\n                                                args: {\r\n                                                    mediaId: mediaId,\r\n                                                },\r\n                                                context,\r\n                                                info\r\n                                            })\r\n                                        }\r\n                                    },\r\n                                },\r\n                            },\r\n                    });\r\n                })\r\n                .catch(error => Logger.Instance().error({\r\n                        errorName: 'SchemaStitchingError',\r\n                        logName: 'GraphQL Schema Stitching Error',\r\n                        cause: error,\r\n                        message: [`Services GraphQl Schema stitching rejected`],\r\n                    })\r\n                );\r\n    }\r\n\r\n    export {Services}`\r\n\r\nthe main schema will be exposed to the end user using `graphqlExpress`\r\nHowever, I could see the extended type in the schema definition.\r\n\r\n\r\n>\"\"\"Media Object\"\"\"\r\ntype Media {\r\n  id: Int\r\n  resource: String\r\n  metadata: Metadata\r\n  discr: String\r\n}\r\n\r\n>\"\"\"Metadata Object\"\"\"\r\ntype Metadata {\r\n  type: String\r\n  format: String\r\n  size: String\r\n}\r\n\r\n\r\n>\"\"\"Publication Type\"\"\"\r\ntype Publication {\r\n  id: ID\r\n  callToAction: CallToAction\r\n  userId: ID\r\n  groupId: ID\r\n  instruction: Instruction\r\n  customizedTitle: String\r\n  content: String\r\n  activityType: ActivityType\r\n  creationTool: CreationTool\r\n  gift: Gift\r\n  imageId: Int\r\n  thumbnailId: Int\r\n  createdAt: Int\r\n  updatedAt: Int\r\n  user: User\r\n  group: Group\r\n  image: Media\r\n  thumbnail: Media\r\n}\r\n\r\n\r\n>type Query {\r\n  getGroupPublications(groupId: Int!, from: Int!, to: Int!): [Publication]\r\n}\r\n\r\n\r\nBut When I try to Query the field `image` of type media using a query defined as \r\n>  query {\r\ngetGroupPublications(groupId:2, from: 1531180800,to: 1532276998) {\r\n      id\r\n      imageId\r\n      image {\r\n        resource\r\n      }\r\n      createdAt\r\n  }\r\n}\r\n\r\nthe query will hit directly the getGroupPublications publications without taking in consideration the mergeSchema and I get this error:\r\n\r\n>{ errors: \r\n>   [ { Cannot query field \"image\" on type \"Publication\". Did you mean \"imageId\"?\r\n>\r\n>GraphQL request (5:3)\r\n>4:     imageId\r\n>5:    image {\r\n>     ^\r\n>6:       resource\r\n>\r\n>    at Object.Field (/home/docker/workspace/api-gateway/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:65:31)\r\n    at Object.enter (/home/docker/workspace/api-gateway/node_modules/graphql/language/visitor.js:324:29)\r\n    at Object.enter (/home/docker/workspace/api-gateway/node_modules/graphql/language/visitor.js:366:25)\r\n    at visit (/home/docker/workspace/api-gateway/node_modules/graphql/language/visitor.js:254:26)\r\n    at visitUsingRules (/home/docker/workspace/api-gateway/node_modules/graphql/validation/validate.js:74:22)\r\n    at validate (/home/docker/workspace/api-gateway/node_modules/graphql/validation/validate.js:59:10)\r\n    at graphqlImpl (/home/docker/workspace/api-gateway/node_modules/graphql/graphql.js:106:50)\r\n    at /home/docker/workspace/api-gateway/node_modules/graphql/graphql.js:66:223\r\n    at new Promise (<anonymous>)\r\n    at Object.graphql (/home/docker/workspace/api-gateway/node_modules/graphql/graphql.js:63:10)\r\n       message: 'Cannot query field \"image\" on type \"Publication\". Did you mean \"imageId\"?',\r\n       locations: [Array],\r\n       path: undefined } ] }\r\n\r\n\r\nBut If I run my query without field `image` it works fine\r\n>query {\r\n  getGroupPublications(groupId:1, from: 1531180800,to: 1532276998) {\r\n    id\r\n    imageId\r\n  }\r\n}\r\n\r\nUpdate ------------------------------------------------------------------------------------------\r\n\r\nI've noticed that this issue occur because we are returning a list Publication Objects where it works fine if my return type is only one publication.\r\n\r\n> getGroupPublications --> returns [Publication] --> type: new GraphQLList(PublicationType).\r\n\r\n"}}
{"actor":{"display_login":"AdelBachene"}}