Similar to #835
Intended outcome:
Publish graph to Apollo Engine using apollo service:push command from the project root, with configuration options provided in projectRoot/apollo.config.js to link a schema from a remote endpoint.
Actual outcome:
apollo.config.js in project root isn't recognized / accepted by the CLI, which appears to default to http://localhost:4000/graphql without alerting the user to an issue with the config file.
For example:
❯ apollo service:push
✔ Loading Apollo Project
✖ Uploading service to Engine
→ request to http://localhost:4000/graphql failed,
…
FetchError: request to http://localhost:4000/graphql failed, reason: connect ECONNREFUSED 127.0.0.1:4000
The only way I've been able to upload the graph to Apollo Engine is by feeding the information provided in the config file directly to the CLI. For example:
❯ apollo service:push --endpoint=my-endpoint-address/graphql --header='x-hasura-admin-secret: my-secret'
✔ Loading Apollo Project
✔ Uploading service to Engine
How to reproduce the issue:
The remote endpoint is a Hasura GraphQL endpoint. The projectRoot/.env file contains the Engine API Key.
projectRoot/apollo.config.js contains the following:
module.exports = {
client: {
service: {
name: 'name-of-my-service',
url: 'path-to-my-remote-service/graphql',
headers: {
'x-hasura-admin-secret': 'my-secret',
},
},
},
};
Running the command with an explicit path to the config file produces an error. The error messages indicates that the config file is malformed, even though it seems to follow the same format as the example given in the docs and other examples. For example:
❯ apollo service:push --config="/path/to/my/projectRoot/apollo.config.js"
› Error: A config file failed to load at '/path/to/my/projectRoot'. This is likely because this file is empty or malformed.
› For more information, please refer to: https://bit.ly/2ByILPj
› at Object.loadConfig (/home/nick/.config/yarn/global/node_modules/apollo-language-server/lib/config/loadConfig.js:43:34)
› at async ServicePush.createConfig (/home/nick/.config/yarn/global/node_modules/apollo/lib/Command.js:59:24)
› at async ServicePush.init (/home/nick/.config/yarn/global/node_modules/apollo/lib/Command.js:44:24)
› at async ServicePush._run (/home/nick/.config/yarn/global/node_modules/@oclif/command/lib/command.js:43:13)
Versions
❯ apollo --version
apollo/2.20.0 linux-x64 node-v12.8.0
This was just a problem with the structure of the apollo.config.js file.
The fact that the CLI command worked when using:
❯ apollo service:push --endpoint=my-endpoint-address/graphql --header='x-hasura-admin-secret: my-secret'
provided some helpful hints about what the structure of the config file had to be (it just needs an endpoint and headers).
The get apollo.config.js working, I had to change from:
module.exports = {
client: {
service: {
name: 'name-of-my-service',
url: 'path-to-my-remote-service/graphql',
headers: {
'x-hasura-admin-secret': 'my-secret',
},
},
},
};
to:
module.exports = {
service: {
endpoint: {
url: 'path-to-my-remote-service/graphql',
headers: {
'x-hasura-admin-secret': 'my-secret',
},
},
},
};
Note that you can use the dotenv package to keep sensitive variables out of your version control. First make sure that HASURA_GRAPHQL_URL and HASURA_ADMIN_SECRET are set alongside the Engine API key in projectRoot/.env. Then in apollo.config.js:
require('dotenv').config();
module.exports = {
service: {
endpoint: {
url: process.env.HASURA_GRAPHQL_URL,
headers: {
'x-hasura-admin-secret': process.env.HASURA_ADMIN_SECRET,
},
},
},
};
My confusion with this issue comes down to not properly distinguishing between setting up a client project vs a server project, as discussed in the docs.
Most helpful comment
Solution
This was just a problem with the structure of the
apollo.config.jsfile.The fact that the CLI command worked when using:
provided some helpful hints about what the structure of the config file had to be (it just needs an endpoint and headers).
The get
apollo.config.jsworking, I had to change from:to:
Note that you can use the dotenv package to keep sensitive variables out of your version control. First make sure that
HASURA_GRAPHQL_URLandHASURA_ADMIN_SECRETare set alongside the Engine API key inprojectRoot/.env. Then inapollo.config.js:My confusion with this issue comes down to not properly distinguishing between setting up a
clientproject vs aserverproject, as discussed in the docs.