Skip to content

Instantly share code, notes, and snippets.

View barsumek's full-sized avatar

Bartosz Sumper barsumek

View GitHub Profile
@barsumek
barsumek / keybase.md
Created September 12, 2019 21:11
Keybase proof

Keybase proof

I hereby claim:

  • I am barsumek on github.
  • I am barsum (https://keybase.io/barsum) on keybase.
  • I have a public key ASBxbJzNQwbpUuw3zvtO0rhfZHGky2ULhInHslnKa3DhOQo

To claim this, I am signing this object:

@barsumek
barsumek / introspectionQuery.txt
Created November 22, 2018 12:42
Detox your GraphQL: Introspection Query
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
types {
...FullType
@barsumek
barsumek / stringTypeMock.js
Created November 22, 2018 12:27
Detox your GraphQL: String type mock
const defaultString = {
String: () => "John Doe"
};
@barsumek
barsumek / PokemonScreenMocked.spec.js
Created November 22, 2018 12:15
Detox your GraphQL: Working test with mocked server
/* eslint-env detox/detox, mocha */
const { defaultPokemon, maxLvlPokemon } = require("../graphql/mocks/pokemon");
const { date } = require("../graphql/mocks/scalars");
const {
startGraphQLServer,
stopGraphQLServer
} = require("../graphql/mockedGraphQLServer");
describe("Test Pokemon screen", () => {
beforeEach(async () => {
@barsumek
barsumek / combineMocks.js
Created November 22, 2018 12:03
Detox your GraphQL: Combining mocks
const { startGraphQLServer } = require("./mockedGraphQLServer");
const { defaultPokemon } = require("./mocks/pokemon");
const { defaultTrainer } = require("./mocks/trainer");
const { date, defaultString } = require("./mocks/scalars");
const customMocks = {
...date,
...defaultString,
...defaultPokemon,
...defaultTrainer
@barsumek
barsumek / mockingDate.js
Last active November 22, 2018 13:45
Detox your GraphQL: Mocking Date scalar type example
const { GraphQLScalarType } = require("graphql");
const { Kind } = require("graphql/language");
const date = {
Date: () => new Date()
};
// for custom scalar types such as Date you need to write resolvers
// then add them to ApolloServer config in startGraphQLServer
const resolvers = {
@barsumek
barsumek / stringTypeMocking.js
Last active November 22, 2018 12:26
Detox your GraphQL: Mocking string type
const defaultString = {
String: () => "John Doe"
};
@barsumek
barsumek / pokemonMock.js
Last active November 22, 2018 13:43
Detox your GraphQL: Mock the Pokemon's level
// Test non-max Pokemon level
{
const defaultPokemon = {
Pokemon: () => ({
level: 10
})
};
//...
await startGraphQLServer({ ...defaultPokemon });
}
function stopHttpServer() {
return new Promise(resolve => httpServer.close(() => resolve()));
}
async function stopGraphQLServer() {
if (!httpServer) {
console.warn("Tried to close null HTTP server.");
return;
}
@barsumek
barsumek / startServerFunctions.js
Created November 22, 2018 10:59
Detox your GraphQL: Functions for starting the server
const express = require("express");
const PORT = 8089;
let graphQLServerApp;
let httpServer;
function startHttpServer() {
return new Promise(resolve => {
httpServer = graphQLServerApp.listen(PORT, () => {