Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

View OlegIlyenko's full-sized avatar

ΘLΞG OlegIlyenko

Passionate software engineer in his journey to perfection
View GitHub Profile
@OlegIlyenko
OlegIlyenko /SangriaMutationExample.scala
Last activeOctober 25, 2019 03:58
Simple example of a mutation with complex input type argument
importsangria.schema._
importsangria.execution._
importsangria.macros._
importsangria.macros.derive._
importsangria.marshalling.circe._
importscala.concurrent.ExecutionContext.Implicits.global
importio.circe.generic.auto._
// Some basic data structures
@OlegIlyenko
OlegIlyenko /SangriaReproExample.scala
Last activeOctober 25, 2019 03:59
An example of minimal self-contained snippet that reproduces specific issue
// Imports that you are using
importsangria.schema._
importsangria.execution._
importsangria.macros._
importsangria.marshalling.circe._
importscala.concurrent.ExecutionContext.Implicits.global
// The schema definition
sealedabstractclassDiscountCodeUpdateAction
caseclassSetDiscountCodeName(name:Option[LocalizedString])
extendsDiscountCodeUpdateAction
caseclassSetDiscountCodeDescription(description:Option[LocalizedString])
extendsDiscountCodeUpdateAction
caseclassSetDiscountCodeCartPredicate(cartPredicate:Option[String])
extendsDiscountCodeUpdateAction
mutationUpdateDC {
updateDiscountCode(
id:"123"
version:5
actions: [
{setName: {name: {locale:"en",value:"10% off"}}}
{changeIsActive: {isActive:false}}
]
) {
id
inputDiscountCodeUpdateAction {
setName:SetDiscountCodeName
setDescription:SetDiscountCodeDescription
setCartPredicate:SetDiscountCodeCartPredicate
setCustomType:SetDiscountCodeCustomType
setCustomField:SetDiscountCodeCustomField
# ...
}
extendtypeMutation {
createDiscountCode(draft:DiscountCodeDraft!):DiscountCode
updateDiscountCode(
id:String!,
version:Long!,
actions: [DiscountCodeUpdateAction!]!):DiscountCode
deleteDiscountCode(id:String!,version:Long!):DiscountCode
}
@OlegIlyenko
OlegIlyenko /CovertJson.scala
CreatedApril 19, 2018 19:50
useful for exception handlers
importsangria.marshalling.MarshallingUtil._
importsangria.marshalling.circe._
valmarchaller:ResultMarshaller=???// provided in ExceptionHandler
valjson:Json=???// your custom json
implicitvalmForType=SimpleResultMarshallerForType[marchaller.Node](marchaller)
valconverted: marchaller.Node= json.convertMarshaled[marchaller.Node]
$(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.
*/
vargraphiql=null
@OlegIlyenko
OlegIlyenko /CirceJsonPath.scala
Last activeMarch 20, 2018 00:29
Stefan Goessner JsonPath (http://goessner.net/articles/JsonPath/) implementation for Circe
// 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")
importcom.jayway.jsonpath.{InvalidJsonException,JsonPathException,Configuration,JsonPath,TypeRef}
importcom.jayway.jsonpath.spi.json.JsonProvider
importcom.jayway.jsonpath.spi.mapper.MappingProvider
@OlegIlyenko
OlegIlyenko /renderSchemaWithLegacyDescriptions.scala
Last activeDecember 19, 2017 17:01
Function to render the schema with legacy comment-based descriptions
importsangria.ast
importsangria.ast.AstVisitor
importsangria.schema._
importsangria.renderer.{QueryRenderer,QueryRendererConfig,SchemaFilter}
importsangria.visitor.VisitorCommand
defrenderSchemaWithLegacyDescriptions(schema:Schema[_, _],filter:SchemaFilter=SchemaFilter.withoutSangriaBuiltIn,config:QueryRendererConfig=QueryRenderer.Pretty)= {
defcommentDescription(node: ast.WithDescription)=
node.description.toVector.flatMap(sv sv.value.split("\\r?\\n").toVector.map(ast.Comment(_)))
NewerOlder

[8]ページ先頭

©2009-2025 Movatter.jp