prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

How to pass a valid token to "graphql get-schema"?

Open marktani opened this issue 8 years ago • 17 comments

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.

marktani avatar Apr 25 '18 15:04 marktani

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".

bazaglia avatar Apr 25 '18 16:04 bazaglia

Ah, can you try yarn graphql get-schema --project db --header "{\"Authorization\": \"Bearer $TOKEN\"}" instead? 🙂

marktani avatar Apr 25 '18 16:04 marktani

@marktani same "Implications failed" error. :(

bazaglia avatar Apr 25 '18 16:04 bazaglia

Thanks for asking @marktani ! You have 2 options:

  1. 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.
  2. Provide the headers as params as you tried, but with the Param=Value syntax
graphql get-schema --project db --header Authorization="Bearer $TOKEN"

timsuchanek avatar Apr 26 '18 07:04 timsuchanek

Thanks @timsuchanek for clearing that up 🙌

marktani avatar Apr 26 '18 12:04 marktani

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

nikolasburk avatar Apr 26 '18 14:04 nikolasburk

@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

huv1k avatar Apr 26 '18 14:04 huv1k

@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 avatar Apr 26 '18 15:04 marktani

@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.

huv1k avatar Apr 26 '18 15:04 huv1k

Can you please create a new issue about this?

marktani avatar Apr 26 '18 15:04 marktani

Made a little suggestion here to have things a little easier (with all those escaped quotes, ughh..)

danielkcz avatar Apr 30 '18 14:04 danielkcz

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.

danielkcz avatar Apr 30 '18 15:04 danielkcz

What dependencies were those? Sounds like we should add that information to the upgrade guide 🙂

marktani avatar Apr 30 '18 15:04 marktani

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 :)

danielkcz avatar Apr 30 '18 15:04 danielkcz

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"
                }
            }
        }
    }
}

andrewjmead avatar Aug 06 '18 14:08 andrewjmead

{
    "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!

Maxondria avatar Nov 25 '19 09:11 Maxondria

It works for me .graphqlconfig.yml file

projects: prisma: schemaPath: src/generated/prisma.graphql extensions: prisma: prisma.yml endpoints: default: http://localhost:4466

MuhammadUmairMoosani avatar Mar 24 '20 08:03 MuhammadUmairMoosani