{"action":"created","issue":{"url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/369","repository_url":"https://api.github.com/repos/prismagraphql/graphql-yoga","labels_url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/369/comments","events_url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/369/events","html_url":"https://github.com/prismagraphql/graphql-yoga/pull/369","id":333901742,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk2MDA1ODI5","number":369,"title":"fix: allow type to be specified on resolver args","user":{"login":"jasonkuhrt","id":284476,"node_id":"MDQ6VXNlcjI4NDQ3Ng==","avatar_url":"https://avatars3.githubusercontent.com/u/284476?v=4","gravatar_id":"","url":"https://api.github.com/users/jasonkuhrt","html_url":"https://github.com/jasonkuhrt","followers_url":"https://api.github.com/users/jasonkuhrt/followers","following_url":"https://api.github.com/users/jasonkuhrt/following{/other_user}","gists_url":"https://api.github.com/users/jasonkuhrt/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonkuhrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonkuhrt/subscriptions","organizations_url":"https://api.github.com/users/jasonkuhrt/orgs","repos_url":"https://api.github.com/users/jasonkuhrt/repos","events_url":"https://api.github.com/users/jasonkuhrt/events{/privacy}","received_events_url":"https://api.github.com/users/jasonkuhrt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-20T02:24:43Z","updated_at":"2018-06-25T03:58:24Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/prismagraphql/graphql-yoga/pulls/369","html_url":"https://github.com/prismagraphql/graphql-yoga/pull/369","diff_url":"https://github.com/prismagraphql/graphql-yoga/pull/369.diff","patch_url":"https://github.com/prismagraphql/graphql-yoga/pull/369.patch"},"body":"Motiving example:\r\n\r\n(Note `Schema.SignupMutationArgs`)\r\n\r\n```ts\r\nimport * as GQLImport from \"graphql-import\"\r\nimport * as Yoga from \"graphql-yoga\"\r\nimport * as YogaTypes from \"graphql-yoga/dist/types\"\r\nimport * as Schema from \"./SchemaTypes\"\r\n\r\nconst typeDefs = GQLImport.importSchema(__dirname + \"/TypeDefs/Main.graphql\")\r\n\r\nconst resolvers: YogaTypes.IResolvers = {\r\n  Mutation: {\r\n    signup: (source: any, args: Schema.SignupMutationArgs, ctx, info) => {\r\n      console.log(args)\r\n      return \"\"\r\n    },\r\n  },\r\n}\r\n\r\nconst server = new Yoga.GraphQLServer({ typeDefs, resolvers })\r\n\r\nserver.start().then(server => {\r\n  console.log(\"started server at %s\", JSON.stringify(server.address()))\r\n})\r\n```\r\n\r\n```\r\nsource/Main.ts(8,7): error TS2322: Type '{ Mutation: { signup: (_: any, args: SignupMutationArgs) => string; }; }' is not assignable to type 'IResolvers'.\r\n  Property 'Mutation' is incompatible with index signature.\r\n    Type '{ signup: (_: any, args: SignupMutationArgs) => string; }' is not assignable to type '(() => any) | IResolverObject | GraphQLScalarType'.\r\n      Type '{ signup: (_: any, args: SignupMutationArgs) => string; }' is not assignable to type 'GraphQLScalarType'.\r\n        Property 'name' is missing in type '{ signup: (_: any, args: SignupMutationArgs) => string; }'.\r\n```\r\n\r\nThis PR fixes the above TS error.\r\n\r\nThe reason for `any` and not just `Record<string,any>` is that we're apparently (surprisingly...) hitting a TS bug:\r\n\r\n* https://stackoverflow.com/questions/46361905/property-is-missing-in-type-x-string-string\r\n* https://github.com/Microsoft/TypeScript/issues/13948\r\n\r\nIf I reduce the union type in Yoga to get at the error (the error message above hits the scaler case because the first two failed, hiding the error message we're interested in):\r\n\r\n```\r\nTSError: ⨯ Unable to compile TypeScript:\r\nsource/Main.ts(8,7): error TS2322: Type '{ Mutation: { signup: (_: any, args: SignupMutationArgs) => string; }; }' is not assignable to type 'IResolvers'.\r\n  Property 'Mutation' is incompatible with index signature.\r\n    Type '{ signup: (_: any, args: SignupMutationArgs) => string; }' is not assignable to type 'IResolverObject'.\r\n      Property 'signup' is incompatible with index signature.\r\n        Type '(_: any, args: SignupMutationArgs) => string' is not assignable to type 'GraphQLFieldResolver<any, any, { [argName: string]: any; }>'.\r\n          Types of parameters 'args' and 'args' are incompatible.\r\n            Type '{ [argName: string]: any; }' is not assignable to type 'SignupMutationArgs'.\r\n              Property 'email' is missing in type '{ [argName: string]: any; }'.\r\n```\r\n\r\nIIUC `              Property 'email' is missing in type '{ [argName: string]: any; }'.` makes no sense because `{ [argName: string]: any; }` should encompass the possibility for any `string` key name :('\r\n\r\nSo alas I am using `any`. Luckily it actually does not seem to matter for the developer as she only really cares at the time of resolver implementation and the Any we're putting here can be overridden as shown in my motivating example."},"comment":{"url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/comments/399823765","html_url":"https://github.com/prismagraphql/graphql-yoga/pull/369#issuecomment-399823765","issue_url":"https://api.github.com/repos/prismagraphql/graphql-yoga/issues/369","id":399823765,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTgyMzc2NQ==","user":{"login":"jasonkuhrt","id":284476,"node_id":"MDQ6VXNlcjI4NDQ3Ng==","avatar_url":"https://avatars3.githubusercontent.com/u/284476?v=4","gravatar_id":"","url":"https://api.github.com/users/jasonkuhrt","html_url":"https://github.com/jasonkuhrt","followers_url":"https://api.github.com/users/jasonkuhrt/followers","following_url":"https://api.github.com/users/jasonkuhrt/following{/other_user}","gists_url":"https://api.github.com/users/jasonkuhrt/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonkuhrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonkuhrt/subscriptions","organizations_url":"https://api.github.com/users/jasonkuhrt/orgs","repos_url":"https://api.github.com/users/jasonkuhrt/repos","events_url":"https://api.github.com/users/jasonkuhrt/events{/privacy}","received_events_url":"https://api.github.com/users/jasonkuhrt/received_events","type":"User","site_admin":false},"created_at":"2018-06-25T03:58:24Z","updated_at":"2018-06-25T03:58:24Z","author_association":"NONE","body":"Hey @schickling or @nikolasburk, did you get a chance to look at this PR yet?"}}
{"actor":{"display_login":"jasonkuhrt"}}