How to use a test/dev environment for Slash GraphQL

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

Here is a link to learn more - Introduction to Firebase Local Emulator Suite.

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.

https://dgraph.io/docs/deploy/download/

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.

J

Um, there isn’t a need to emulate it. Slash GraphQL is simply Dgraph. You can run Dgraph locally

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

  1. Obtain a copy of my Slash Dgraph schema (to ensure it gets the latest one)
  2. Allow me to inject variables into the # Dgraph.Authorization object in the schema
  3. Provide a url I can use to query/mutate the database (acting as if I was calling my Slash GraphQL url)
  4. A script/command to easily drop all of the data in the database (but keep the schema and Authorisation object)
  5. 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.

To get me started I might follow this tutorial and see if I can create what I am looking for - GitHub - dgraph-io/dgraph-js: Official Dgraph JavaScript client

Check out Dgraph λ and the instructions.

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)

The URL would mostly be localhost:8000/graphql

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.

J