Closed asherccohen closed 3 years ago
I don't think the problem is caused by using env variables. Does it work well when you write IP addresses manually? fetchache
is our internal library that handles HTTP requests by respecting cache headers like browsers but on the server side. :)
https://unpkg.com/@graphql-mesh/openapi@0.10.13/index.cjs.js I can see the correct code in here. Maybe you're using an old version.
I don't think the problem is caused by using env variables. Does it work well when you write IP addresses manually?
fetchache
is our internal library that handles HTTP requests by respecting cache headers like browsers but on the server side. :)https://unpkg.com/@graphql-mesh/openapi@0.10.13/index.cjs.js I can see the correct code in here. Maybe you're using an old version.
Ok true, I did update packages but some weird cache might have got into the way, a nice wipeout of the node_modules did the trick and now optional chaining is compiled correctly and I passed over the "Cannot read property 'title' of undefined" error even with env variables. Surely and issue that was already fixed.
Great, thanks for that.
I need to reopen this to clarify a point.
I have this command to generate the types. "mesh:ts": "graphql-mesh typescript --output ./src/mesh/generated/types.ts"
Once again, if I run this with an env variable set I get:
graphql-mesh typescript
Generates TypeScript typings for the generated mesh
Options:
--version Show version number [boolean]
--help Show help [boolean]
-r, --require Loads specific require.extensions before running the codegen
and reading the configuration [array] [default: []]
--output [string] [required]
[Error: ENOENT: no such file or directory, stat '/api.yaml'] {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/api.yaml'
}
Path is again missing the endpoint from env vars.
I think you want to load environmental variables from .env file. You need to load dotenv with require parameter;
graphql-mesh typescript --require dotenv/config --output ./src/mesh/generated/types.ts
Brilliant, tx!
Versions:
Context: .meshrc.yaml file can be written with interpolation of environment variables so that one can keep IPs and other tokens in an .env file. This is particularly useful for CI/CD and other staging automation. Dotenv package needs to be installed and imported in server index file like in this codesandbox: https://codesandbox.io/s/musing-tree-8voqb?file=/src/index.ts:0-23
Behavior: When a source is set with env variables I get this error:
I have tracked down the source of the issue to this line: https://github.com/Urigo/graphql-mesh/blob/master/packages/utils/src/read-file-or-url.ts#L69 (side note, fetchache looks like a typo).
Then in fetchache (can't find it in the the github repo sorry) I see:
PS. Finally I also noticed that at this line: https://github.com/Urigo/graphql-mesh/blob/master/packages/handlers/openapi/src/openapi-to-graphql/index.ts#L705 There is a usage of optional chaining which is not compiled correctly as it is kept as:
while it should compile to something like: