Instantly share code, notes, and snippets.
Passionate software engineer in his journey to perfection
- localhost
- https://medium.com/@oleg.ilyenko
OlegIlyenko /SangriaMutationExample.scala
Last activeOctober 25, 2019 03:58
Simple example of a mutation with complex input type argument This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 /SangriaReproExample.scala
Last activeOctober 25, 2019 03:59
An example of minimal self-contained snippet that reproduces specific issue This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// Imports that you are using | |
importsangria.schema._ | |
importsangria.execution._ | |
importsangria.macros._ | |
importsangria.marshalling.circe._ | |
importscala.concurrent.ExecutionContext.Implicits.global | |
// The schema definition |
OlegIlyenko /DiscountCodeUpdateAction.scala
Last activeOctober 25, 2019 03:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
sealedabstractclassDiscountCodeUpdateAction | |
caseclassSetDiscountCodeName(name:Option[LocalizedString]) | |
extendsDiscountCodeUpdateAction | |
caseclassSetDiscountCodeDescription(description:Option[LocalizedString]) | |
extendsDiscountCodeUpdateAction | |
caseclassSetDiscountCodeCartPredicate(cartPredicate:Option[String]) | |
extendsDiscountCodeUpdateAction |
OlegIlyenko /DiscountCodeUpdateExample.graphql
CreatedApril 25, 2018 20:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
mutationUpdateDC { | |
updateDiscountCode( | |
id:"123" | |
version:5 | |
actions: [ | |
{setName: {name: {locale:"en",value:"10% off"}}} | |
{changeIsActive: {isActive:false}} | |
] | |
) { | |
id |
OlegIlyenko /DiscountCodeUpdateActions.graphql
Last activeOctober 25, 2019 03:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
inputDiscountCodeUpdateAction { | |
setName:SetDiscountCodeName | |
setDescription:SetDiscountCodeDescription | |
setCartPredicate:SetDiscountCodeCartPredicate | |
setCustomType:SetDiscountCodeCustomType | |
setCustomField:SetDiscountCodeCustomField | |
# ... | |
} |
OlegIlyenko /DiscountCodeMutations.graphql
Last activeOctober 25, 2019 03:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
extendtypeMutation { | |
createDiscountCode(draft:DiscountCodeDraft!):DiscountCode | |
updateDiscountCode( | |
id:String!, | |
version:Long!, | |
actions: [DiscountCodeUpdateAction!]!):DiscountCode | |
deleteDiscountCode(id:String!,version:Long!):DiscountCode | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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] |
OlegIlyenko /app-graphiql.js
CreatedApril 16, 2018 15:32
enabling profiling in graphiql (diff againsthttps://github.com/sangria-graphql/sangria-playground/blob/68382f961e002f468511d9e8a93ccb3623cb46b3/public/javascripts/app-graphiql.js) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
$(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 /CirceJsonPath.scala
Last activeMarch 20, 2018 00:29
Stefan Goessner JsonPath (http://goessner.net/articles/JsonPath/) implementation for Circe This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// 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 /renderSchemaWithLegacyDescriptions.scala
Last activeDecember 19, 2017 17:01
Function to render the schema with legacy comment-based descriptions This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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