Skip to content

[RFC]: Support for environment variables #1

@ulisses-cruz

Description

@ulisses-cruz

Reason

In order to be safely able to share the files with the queries used by this plugin, it is necessary to add support for environment variables.

That way, it will not be needed to erase sensitive data before pushing the files to a repository our sharing it in other ways.

How it would work

You would put the environment variables in the metadata of a query. It would start with the character $, (the same way variables are represented in graphql):

# variables: {
#   "code": "$CODE"
# }
query Country($code: ID!) {
  country(code: $code) {
    code
    name
  }
}

The plugin would try to find the file where the variables are set in a list called env_paths. This list would be configured in the plugin's setup function.

gql.setup {
    filetypes = { 'graphql' },
    keymaps = {
        run = '<leader>rr',
    },
    env_pats = { "path/to/.env" }
}

The paths in the list could be absolute or relative to the file being executed.

Error or no error

  • If there is no environment variable found in the query metadata, there is no need to read the .env_file;
  • If the environment variable is not found in the .env_file, it is not substituted and no error is shown;
  • If the .env_file is not found, no environment variable is substituted and no error is shown;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions