Skip to content

Instantly share code, notes, and snippets.


ΘLΞG OlegIlyenko

View GitHub Profile
OlegIlyenko / SangriaMutationExample.scala
Last active Oct 25, 2019
Simple example of a mutation with complex input type argument
View SangriaMutationExample.scala
import sangria.schema._
import sangria.execution._
import sangria.macros._
import sangria.macros.derive._
import sangria.marshalling.circe._
// Some basic data structures
OlegIlyenko / SangriaReproExample.scala
Last active Oct 25, 2019
An example of minimal self-contained snippet that reproduces specific issue
View SangriaReproExample.scala
// Imports that you are using
import sangria.schema._
import sangria.execution._
import sangria.macros._
import sangria.marshalling.circe._
// The schema definition
View DiscountCodeUpdateAction.scala
sealed abstract class DiscountCodeUpdateAction
case class SetDiscountCodeName(name: Option[LocalizedString])
extends DiscountCodeUpdateAction
case class SetDiscountCodeDescription(description: Option[LocalizedString])
extends DiscountCodeUpdateAction
case class SetDiscountCodeCartPredicate(cartPredicate: Option[String])
extends DiscountCodeUpdateAction
View DiscountCodeUpdateExample.graphql
mutation UpdateDC {
id: "123"
version: 5
actions: [
{setName: {name: {locale: "en", value: "10% off"}}}
{changeIsActive: {isActive: false}}
) {
View DiscountCodeUpdateActions.graphql
input DiscountCodeUpdateAction {
setName: SetDiscountCodeName
setDescription: SetDiscountCodeDescription
setCartPredicate: SetDiscountCodeCartPredicate
setCustomType: SetDiscountCodeCustomType
setCustomField: SetDiscountCodeCustomField
# ...
View DiscountCodeMutations.graphql
extend type Mutation {
createDiscountCode(draft: DiscountCodeDraft!): DiscountCode
id: String!,
version: Long!,
actions: [DiscountCodeUpdateAction!]!): DiscountCode
deleteDiscountCode(id: String!, version: Long!): DiscountCode
OlegIlyenko / CovertJson.scala
Created Apr 19, 2018
useful for exception handlers
View CovertJson.scala
import sangria.marshalling.MarshallingUtil._
import sangria.marshalling.circe._
val marchaller: ResultMarshaller = ??? // provided in ExceptionHandler
val json: Json = ??? // your custom json
implicit val mForType = SimpleResultMarshallerForType[marchaller.Node](marchaller)
val converted: marchaller.Node = json.convertMarshaled[marchaller.Node]
View app-graphiql.js
$(function (global) {
* This GraphiQL example illustrates how to use some of GraphiQL's props
* in order to enable reading and updating the URL parameters, making
* link sharing of queries a little bit easier.
* This is only one example of this kind of feature, GraphiQL exposes
* various React params to enable interesting integrations.
var graphiql = null
OlegIlyenko / CirceJsonPath.scala
Last active Mar 20, 2018
Stefan Goessner JsonPath ( implementation for Circe
View CirceJsonPath.scala
// For build.sbt:
// libraryDependencies ++= Seq(
// "io.circe" %% "circe-core" % "0.9.2",
// "io.circe" %% "circe-parser" % "0.9.2",
// "com.jayway.jsonpath" % "json-path" % "2.3.0")
import com.jayway.jsonpath.{InvalidJsonException, JsonPathException, Configuration, JsonPath, TypeRef}
import com.jayway.jsonpath.spi.json.JsonProvider
import com.jayway.jsonpath.spi.mapper.MappingProvider
OlegIlyenko / renderSchemaWithLegacyDescriptions.scala
Last active Dec 19, 2017
Function to render the schema with legacy comment-based descriptions
View renderSchemaWithLegacyDescriptions.scala
import sangria.ast
import sangria.ast.AstVisitor
import sangria.schema._
import sangria.renderer.{QueryRenderer, QueryRendererConfig, SchemaFilter}
import sangria.visitor.VisitorCommand
def renderSchemaWithLegacyDescriptions(schema: Schema[_, _], filter: SchemaFilter = SchemaFilter.withoutSangriaBuiltIn, config: QueryRendererConfig = QueryRenderer.Pretty) = {
def commentDescription(node: ast.WithDescription) =
node.description.toVector.flatMap(sv sv.value.split("\\r?\\n")