Is it possible to have an emulated version of Slash GraphQL or something locally we can use when developing our apps or running tests? I am migrating away from Firebase which has a brilliant local emulator that takes a copy a backend environment and provides an offline version to use (it also includes handling things like auth).
If this isn’t possible, are they are best practices with Slash GraphQL for local development and to run tests like end to end tests? Unit tests are easy as it makes sense to mock the responses but for end to end tests I find it is always better to keep the environment as close to production as possible (hence use a database instead of mocked responses). At the moment I think the best approach would be to create another backend (on the free tier) and copy across my production schema.
I think Firebase needs the Emulator because you can’t download it locally. Dgraph is open source, and can be downloaded locally and run VIA a docker to get what you want.
However, that defeats the purpose of non managing all that yourself, hence Cloud Dgraph. I would suggest a second version as you said. I have, however, gone over my limits just testing. Personally, I am happy to pay $10 a month for an extra testing platform, as I want to support the developers and Dgraph team with the great product that it is.
You could have two Firebase Auth platforms for free to test that as well.
Are there any examples of this I can reference? I can’t seem to find an example that has the following functionality (preferably in Javascript/Typescript):
Obtain a copy of my Slash Dgraph schema (to ensure it gets the latest one)
Allow me to inject variables into the # Dgraph.Authorization object in the schema
Provide a url I can use to query/mutate the database (acting as if I was calling my Slash GraphQL url)
A script/command to easily drop all of the data in the database (but keep the schema and Authorisation object)
Be able to run the above steps on a local computer (eg MacOS) and also in a CI pipeline (eg Github Actions)
I love using Slash GraphQL as it is fully managed hence why I am trying to find the equivalent that I can use locally.
As for copying of your data, I don’t think you can do that (I mean you can probably set up something fancy with learner nodes in 21.03, but I suspect it will be a fairly involved thing)
Slash GraphQL CLI does this, although it does not work right now until Dgraph figures out what direction they want to go:
You inject variables variables in your header call to graphql. If you’re using a local version, it would work the same way. You could also inject variables in a local lambdas, which is somewhat the equivalent to firebase functions. See chewxy’s answer.
See chewxy’s answer
The authorization object, would just run once and work as expected. It depends on what you’re trying to do here. You could literally just use firebase auth emulator for your needs here. Dgraph does not handle authorizations directly, hence you need auth0 or firebase.
Slash graphql cli drops data, but again, it does not work and I am not sure their plans on fixing this or adding a new similar functionality.
Dgraph can run on a local machine with a docker as stated. I don’t see why this couldn’t work in a CI pipeline as well.
In theory, you could do all of this with DGraph. However, I don’t know it has ever been done before quite like you stated.
Just to follow up with this, is there a docker file (I can’t see any in the docs) I can use to start up a local copy of dgraph and access it via a graphql client/admin endpoint? I am looking for something like this (this is provided by Hasura) - https://hasura.io/docs/latest/graphql/core/getting-started/docker-simple.html/.
I have noticed the docs are not very clear on how to set up a local environment at all. For example they have links like this: https://dgraph.io/docs/graphql/admin/#modifying-a-schema, but when you try to run the suggested commands with the default docker-compose file they error. For example trying to upload a schema errors with:
{"errors":[{"message":"resolving updateGQLSchema failed because unauthorized ip address: ... (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}
Does anyone have any tutorials, guides or setups on how to get a local dev environment working? I am looking to do this so that I can reduce costs in having multiple Dgraph Cloud accounts that I only use to run tests in CI and develop with locally.
I am sure my situation isn’t unique and other people would be wanting this too. What I am looking for is when I start my day coding I have can:
Spin up dgraph locally and connect to its graphql endpoint (so far I can do this with the default docker-compose)
Have a script to replace the schema with an updated one
Have a script to export a copy of the database
Have a script to import an exported copy of the database
Run all of the above locally, and in CI (Github Actions)