graphql-typed-client
graphql-typed-client copied to clipboard
Custom scalar type mapping does not work with relative paths on Windows
The example in the README for a custom scalar type mapping does not work on Windows.
module.exports = {
endpoint: 'http://example.com/graphql',
output: 'clients/myClient',
options: { typeMapper: { location: 'path/to/typeMapper', types: ['Date'] } },
}
The problem is that the output and typeMapper's location are different, so a relative path will be generated (in relativeImportPath.ts). In this case, the relative path would be '../../path/to/typeMapper'
However, the code uses path.relative() to generate that path, which is OS-dependant: Node documentation. On Windows, this will generate the string '..\..\path\to\typeMapper', which is not a valid Node import string. Instead, use path.posix.relative() to force POSIX-compliant paths, even on Windows.