Skip to content

Instantly share code, notes, and snippets.

ΘLΞG OlegIlyenko

Block or report user

Report or block OlegIlyenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@OlegIlyenko
OlegIlyenko / SangriaMutationExample.scala
Last active Sep 10, 2018
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._
import scala.concurrent.ExecutionContext.Implicits.global
import io.circe.generic.auto._
// Some basic data structures
@OlegIlyenko
OlegIlyenko / SangriaReproExample.scala
Last active Aug 13, 2018
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._
import scala.concurrent.ExecutionContext.Implicits.global
// 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 {
updateDiscountCode(
id: "123"
version: 5
actions: [
{setName: {name: {locale: "en", value: "10% off"}}}
{changeIsActive: {isActive: false}}
]
) {
id
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
updateDiscountCode(
id: String!,
version: Long!,
actions: [DiscountCodeUpdateAction!]!): DiscountCode
deleteDiscountCode(id: String!, version: Long!): DiscountCode
}
@OlegIlyenko
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
OlegIlyenko / CirceJsonPath.scala
Last active Mar 20, 2018
Stefan Goessner JsonPath (http://goessner.net/articles/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
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").toVector.map(ast.Comment(_)))
You can’t perform that action at this time.