← Заметки

· заметки

Should We Expect Much from GraphQL?

GraphQL offers numerous benefits, including static analysis, codegen tools, a playground, and built-in documentation. While some developers struggle with GraphQL due to poor API design choices, I’d like to introduce a simple yet powerful approach that makes development process straightforward.

  • % incorporates all the best practices recommended by Martin Fowler.

Let’s say, we need to automate an existing business process. While it may not be technically complex, it does involve diverse domain. After gathering requirements and documenting user flows, we can begin designing the API and underpin it with example scenarios.

mutation setup {
	createWarehouse(form: {
		address: "50 The Drive"
		postal: "W75 4LM"
	}) {
		id @shouldBeNotNull
	}
}

mutation action {
	createOrder(form: {
		sourceId: 1
		destinationId: 1
		volumeM3: 1.6
		weightKg: 23.5
	}) {
		status @shouldEqual(to: NEW)
	}
}

query check {
    order(id: 1) @shouldMatchSnapshot {
        status @shoualEqual(to: NEW)
    }
}
mutation setup {
	createConcert(name: "Charlie Parker")

    createUser(name: "Bob") {
	    id
    }
}

You may have noticed @shouldEqual(to: NEW), a custom directive that repeats

Here is a custom directive. It puts an emphasis on the value a user gets after running the scenario. On the other hand, it’s a tool for QA to ensure system’s completeness and consistency with explicit contracts.

- place_an_order.graphql
- send_orders_to_supplier.graphql
- tariffy_orders_then_print_invoice.graphql
- try_canceling_invoiced_order.graphql

These files are stored in the code repository. Everyone in the team has access and knows how to communicate using the same language.

a system analyst, frontend, backend, QA, a project manager, a product owner.

  • the whole team speaks the single language — each user flow is described as a GraphQL test suit

  • % rework the example, remove city, add invoice?

  • % cons with external integrations

  • mustBeEqual and shouldBeEqual

  • not so good with integrations

  • asks how to test graphql handlers: https://stackoverflow.com/q/75845659/3160483

  • как тестить в случае event driven архитектуры? (очередь етц)