{"action":"created","issue":{"url":"https://api.github.com/repos/apollostack/graphql-tools/issues/162","repository_url":"https://api.github.com/repos/apollostack/graphql-tools","labels_url":"https://api.github.com/repos/apollostack/graphql-tools/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/apollostack/graphql-tools/issues/162/comments","events_url":"https://api.github.com/repos/apollostack/graphql-tools/issues/162/events","html_url":"https://github.com/apollostack/graphql-tools/issues/162","id":179540392,"number":162,"title":"Mocking Scalar types?","user":{"login":"pierlo-upitup","id":1078545,"avatar_url":"https://avatars.githubusercontent.com/u/1078545?v=3","gravatar_id":"","url":"https://api.github.com/users/pierlo-upitup","html_url":"https://github.com/pierlo-upitup","followers_url":"https://api.github.com/users/pierlo-upitup/followers","following_url":"https://api.github.com/users/pierlo-upitup/following{/other_user}","gists_url":"https://api.github.com/users/pierlo-upitup/gists{/gist_id}","starred_url":"https://api.github.com/users/pierlo-upitup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierlo-upitup/subscriptions","organizations_url":"https://api.github.com/users/pierlo-upitup/orgs","repos_url":"https://api.github.com/users/pierlo-upitup/repos","events_url":"https://api.github.com/users/pierlo-upitup/events{/privacy}","received_events_url":"https://api.github.com/users/pierlo-upitup/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-27T16:14:02Z","updated_at":"2016-09-27T18:16:52Z","closed_at":null,"body":"Hi there and thanks for this awesome tool. I'm new to GraphQL so this may be a complete facepalm on my end, in which case feel free to close this issue.\r\n\r\nI have a GraphQL schema that declares a `Scalar` type used by a specific field.\r\nWhen I define the mock for it though, this seems to be ignored.\r\n\r\n\r\nExample:\r\n\r\n(schema)\r\n```\r\nscalar Currency \r\n\r\n  type User {\r\n    id: ID!\r\n    name: String\r\n    currency: Currency\r\n  }\r\n```\r\n\r\n(mock)\r\n```\r\nconst server = mockServer(shorthand, {\r\n  RootQuery: () => ({\r\n    user: (o, { id }) => ({ id })\r\n  }),\r\n  Currency: ()  => casual.double(0, 1000),\r\n  User: () => ({\r\n    name: casual.full_name,\r\n    currency: casual.double(0, 10000),\r\n    lists: () => new MockList(3, (user) => ({ owner: user.id })),\r\n  }),\r\n});\r\n```\r\n\r\n(query)\r\n```\r\nquery tasksForUser{\r\n  user(id: 6) {\r\n    id\r\n    name\r\n    currency\r\n  }\r\n}\r\n```\r\n\r\nTo reproduce simply add the currency field to https://github.com/apollostack/mock-demo/blob/master/app/index.js#L12 and replace the GraphiQL query alongside with the mock definition above.\r\n\r\nThat will return:\r\n\r\n```\r\n{\r\n  \"data\": {\r\n    \"user\": {\r\n      \"id\": \"6\",\r\n      \"name\": \"Bridie Ferry\",\r\n      \"currency\": null\r\n    }\r\n  }\r\n}\r\n``` \r\n(note the `\"currency\": null`).\r\n\r\n\r\nIt seems like neither the `Currency` type definition, nor the `User.currency` field definition are actually used. \r\nAdditionally, if the `currency: Currency` field would be made not-nullable (ie `currency: Currency!`) the query would return an error:\r\n\r\n`\"message\": \"Cannot return null for non-nullable field User.currency.\",`\r\n\r\n\r\nCould you please clarify how to mock Scalar definitions? Thanks!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apollostack/graphql-tools/issues/comments/249951031","html_url":"https://github.com/apollostack/graphql-tools/issues/162#issuecomment-249951031","issue_url":"https://api.github.com/repos/apollostack/graphql-tools/issues/162","id":249951031,"user":{"login":"DxCx","id":1080411,"avatar_url":"https://avatars.githubusercontent.com/u/1080411?v=3","gravatar_id":"","url":"https://api.github.com/users/DxCx","html_url":"https://github.com/DxCx","followers_url":"https://api.github.com/users/DxCx/followers","following_url":"https://api.github.com/users/DxCx/following{/other_user}","gists_url":"https://api.github.com/users/DxCx/gists{/gist_id}","starred_url":"https://api.github.com/users/DxCx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DxCx/subscriptions","organizations_url":"https://api.github.com/users/DxCx/orgs","repos_url":"https://api.github.com/users/DxCx/repos","events_url":"https://api.github.com/users/DxCx/events{/privacy}","received_events_url":"https://api.github.com/users/DxCx/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T18:16:52Z","updated_at":"2016-09-27T18:16:52Z","body":"Here is an example:\r\n```typescript\r\n Currency: {\r\n  __parseValue(value) {\r\n    return value;\r\n  },\r\n  __serialize(value) {\r\n    return value;\r\n  },\r\n  __parseLiteral(ast) {\r\n    if (ast.kind !== Kind.FLOAT) {\r\n      throw new GraphQLError(`Query error: Can only parse float got a: ${ast.kind}.`, [ast]);\r\n    }\r\n\r\n    const parsed = parseFloat(ast.value);\r\n    return parsed;\r\n  },\r\n```"}}
{"actor":{"display_login":"DxCx"}}