Hi guys, thanks in advance for reading this. Does everyone know how to solve my problem?
I have a product data type in my code that looks like this:
final case class Choice(id: Int, name: String, option: ChoiceOption)
sealed trait ChoiceOption
object ChoiceOption {
final case class SingularChoiceOption(checked: Boolean) extends ChoiceOption
final case class MultipleChoiceOption(possibleValues: Seq[String], defaultValue: String) extends ChoiceOption
}
I want to represent this code in sangria as an interface:
interface Choice {
id: Int!
name: String!
}
type SingularChoice implements Choice {
id: Int!
name: String!
checked: Boolean!
}
type MultipleChoiceOption implements Choice {
id: Int!
name: String!
possibleValues: [String!]!
defaultValue: String!
}
but I don't want to write my code like this:
sealed trait Choice {
val id: Int
val name: String
}
final case class SingularChoiceOption(id: Int, name: String, checked: Boolean) extends Choice
final case class MultipleChoiceOption(id: Int, name: String, possibleValues: Seq[String], defaultValue: String) extends Choice
I'm using InterfaceType
for describing my Choice, but there're no constructors that resolve value as an interface subtype. In other words, I want to view product data type as a sum data type.
Does anyone know workarounds for this case? Thank you =).
In developing a Sangria example, I'm having difficulty in demonstrating even the most basic use of an SDL-based schema materialization. I'm getting
sangria.schema.SchemaMaterializationException: Can't extract value for a field 'User.id': not a map-like value.
when I use an SDL file containing
type User {
id: Long!
name: String!
person: Person!
}
I find it odd that ScalaInputUnmarshaller.isMapNode()
is true
only for Map
s, not for case classes, or that my User
case class doesn't get treated like a map. Wondering whether there's some linkage in the Scala code that I need.
The examples that I see tend to define the schema in Scala code. That has worked for me, but it obfuscates the schema's design. So it seems a real shame to do it that way.
Anyway, just mentioning the error for now, in case someone else has seen it. I'll have a clean example of the failure published soon.
InputObjectType
is used to represent a GraphQL type that can be used as an input, for example for an argument.hi everybody! Could you please help me. I have graphql query and schema. What is the best way to analyze query and retrieve all requested fileds with proper type? For example in recursive structure:
sealed trait GraphQlFieldType {
val typeName: String
}
final case class GraphQlField(name: String, fieldType: GraphQlFieldType, isArray: Boolean = false)
final case class GraphQlFieldTypeDataClass(typeName: String,
fields: List[GraphQlField]) extends GraphQlFieldType
SubscriptionContext
without transactions or do you guys have another suggestion?
Action
s?
"data": {
"getCar:[
{
"car": {
“id”: “111”
}
}
]
},
"errors": [
{
"message": “Couldn’t find data for car”
"code":"404"
“fields” : ”000,222”
}
]
}
Suppose I have the following schema:
lazy val ParentType = ObjectType(
"Parent",
collect[...](
Public(
Field("child", ChildType,
resolve = _.value.child
)
)
)
)
lazy val ChildType = ObjectType(
"Child",
collect[...](
Public(
Field("something", StringType,
resolve = ...
)
)
)
)
Is there a way to reference a field in the parent value/type within the resolve method of the ChildType's "something" resolve field.
I'm trying to do some custom instrumentation in New Relic similar to their recent graphql-java instrumentation:
https://github.com/newrelic/newrelic-java-agent/blob/5a035c11d3b0226655468d780c38342a60e790a7/instrumentation/graphql-java-16.2/src/main/java/com/nr/instrumentation/graphql/GraphQLSpanUtil.java#L39
What would be the equivalent of graphql-java's graphql.execution.ExecutionStrategyParameters
? Can I derive it from sangria.ast.Document
https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/execution/ExecutionStrategyParameters.java
NoClassDefFoundError: sangria/parser/DeliveryScheme
https://gist.github.com/jgillich/3e8d90dde7526d47a5f5fe496aae9889can someone help me with the mutation?
Schema
implicit val inComercioType = deriveObjectType[DataRepo, comercio]()
val ComercioInObject = {
InputObjectType(
name = "Insert Comercio",
description = "",
List(
InputField(
name = "condicion",
fieldType = StringType),
InputField(
name = "laltitud",
fieldType = BigDecimalType),
InputField(
name = "longitud",
fieldType = BigDecimalType),
InputField(
name = "distancia",
fieldType = IntType),
)
)
}
val Condicion: Argument[String] = Argument("condicion", StringType)
val Latitud: Argument[BigDecimal] = Argument("latitud", BigDecimalType)
val Longitud: Argument[BigDecimal] = Argument("longitud", BigDecimalType)
val Distancia: Argument[Int] = Argument("distancia", IntType)
val MutationType =
ObjectType(
"Mutation",
fields[DataRepo, Unit](
Field(
name ="addComercios",
fieldType = ComercioOutObject,
arguments = Condicion :: Latitud :: Longitud :: Distancia :: Nil,
resolve = c => c.ctx.gqlAddComercios(c.arg(Condicion),c.arg(Latitud) ,c.arg(Longitud),c.arg(Distancia))
),
)
)
val SchemaDefinition: Schema[DataRepo, Unit] = Schema(QueryType,Some(MutationType))
Datarepo
def gqlAddComercios(condicion: String,latitud:BigDecimal,longitud:BigDecimal,distancia:Int=250):List[getComercio] = comercio(condicion,latitud,longitud,distancia,token).insertContent