How to pass a valid token to "graphql get-schema"?
With 1.7, I can now set a post deployment hook to download the Prisma API schema:
# prisma.yml
hooks:
post-deploy:
- graphql get-schema --project db
However, this leads to an error message about an invalid token for secret-protected Prisma services.
How can I change this command to add a new prisma token on the fly?
I thought of something like this:
# prisma.yml
hooks:
post-deploy:
- TOKEN=Bearer ${prisma token}
- graphql get-schema --header "{"Authorization": "${TOKEN}"}
I don't think this syntax works though.
The valid syntax for yml is:
hooks:
post-deploy:
- TOKEN=$(prisma token)
- yarn graphql get-schema --header "{\"Authorization\": \"Bearer $TOKEN\"}"
However I'm not sure the --header param graphql-cli expect is correct as it says: "Implications failed: --no-endpoint -> --no-header".
Ah, can you try yarn graphql get-schema --project db --header "{\"Authorization\": \"Bearer $TOKEN\"}" instead? 🙂
@marktani same "Implications failed" error. :(
Thanks for asking @marktani ! You have 2 options:
- Use the
.graphqlconfig.ymlIf you have defined your prisma endpoint in the.graphqlconfig.yml, just providing--projectshould be enough and thegraphql-config-extension-prismashould provide the auth headers. If that's not the case, it's a bug. - Provide the headers as params as you tried, but with the
Param=Valuesyntax
graphql get-schema --project db --header Authorization="Bearer $TOKEN"
Thanks @timsuchanek for clearing that up 🙌
This worked for me:
graphql get-schema \
--endpoint https://eu1.prisma.sh/public-lucksight-113/myservice/dev \
--header Authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJkYXRhYmFzZUBkZXYiLCJyb2xlcyI6WyJhZG1pbiJdfSwiaWF0IjoxNTI0NzUyNjQyLCJleHAiOjE1MjUzNTc0NDJ9.ricwDHJoHtmYN8ZD4ldjH3ek_YMIUJqervXZ0ApjYpU \
--output prisma.graphql
@timsuchanek With second option I get:Unknown argument: header, even in help graphql get-schema --help there is nothing about headers i have 2.3.0 version
@nikolasburk, thanks for sharing! It should be noted however that this doesn't work as post deployment hook, because your token will eventually expire if you hardcode it.
@Huvik, 2.3.0 is quite old. If you're on [email protected], you should go with [email protected] (or higher), if you're on [email protected], with [email protected].
@marktani Yea, looks like that hooks take graphql-cli globally installed packages and prisma globally installed don't update global packages :( But I still get errors with unhandled promises.
Can you please create a new issue about this?
Made a little suggestion here to have things a little easier (with all those escaped quotes, ughh..)
Use the .graphqlconfig.yml If you have defined your prisma endpoint in the .graphqlconfig.yml, just providing --project should be enough and the graphql-config-extension-prisma should provide the auth headers. If that's not the case, it's a bug.
I think this is indeed a bug as it asked me for a token on several occasions already. Need to test bit more though, I am not sure if it was before I updated other dependencies that were not mentioned in upgrade guide.
What dependencies were those? Sounds like we should add that information to the upgrade guide 🙂
I've updated graphql-yoga, prisma-binding, graphql-cli along with prisma. Not sure which one is really needed, I just needed to make it working :)
If you have defined your prisma endpoint in the .graphqlconfig.yml, just providing --project should be enough and the graphql-config-extension-prisma should provide the auth headers. If that's not the case, it's a bug.
I was able to get that to work, but only after adding a prisma property to the extensions object in.graphqlconfig. I'm leaving this here for anyone else who might have run into the same issue.
Here's my before file where I was getting the auth token error:
{
"projects": {
"prisma": {
"schemaPath": "src/generated/prisma.graphql",
"extensions": {
"endpoints": {
"default": "http://localhost:4466"
}
}
}
}
}
Here's the final config file which no longer crashes due to a lack of an auth token:
{
"projects": {
"prisma": {
"schemaPath": "src/generated/prisma.graphql",
"extensions": {
"prisma":"prisma/prisma.yml",
"endpoints": {
"default": "http://localhost:4466"
}
}
}
}
}
{ "projects": { "prisma": { "schemaPath": "src/generated/prisma.graphql", "extensions": { "prisma":"prisma/prisma.yml", "endpoints": { "default": "http://localhost:4466" } } } } }
Works like charm... and it sure had to be you @andrewjmead , you are a genius... You teach more than my college professors * 100000... Keep on... You 're amazing! Coming to buy your Prisma course very very soon on udemy! I need more clarity, that's why... I know I will understand better.... Cheers!
It works for me .graphqlconfig.yml file
projects: prisma: schemaPath: src/generated/prisma.graphql extensions: prisma: prisma.yml endpoints: default: http://localhost:4466