Skip to content

Commit

Permalink
Revert "Support custom scalars for Pure Integer type during GraphQL S…
Browse files Browse the repository at this point in the history
…DL generation (#2500)" (#2586)

This reverts commit d0f5f8c.
  • Loading branch information
MauricioUyaguari authored Jan 29, 2024
1 parent 3dd8572 commit 4ae864f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,32 @@ function meta::external::query::graphQL::binding::fromInterfaceTypeName(interfac
if($interfaceTypeName->endsWith('Interface'), | $interfaceTypeName->substring(0, $interfaceTypeName->length() - 9), | '')
}

Class meta::external::query::graphQL::binding::PureTypeToGraphQLScalarOverride
function meta::external::query::graphQL::binding::purePrimitivesToGraphQLScalarTypes(): Pair<PrimitiveType,String>[*]
{
integerScalarType: String[0..1];
[
pair(String, 'String'),
pair(Integer, 'Int'),
pair(Float, 'Float'),
pair(Boolean, 'Boolean')
]
}

function meta::external::query::graphQL::binding::purePrimitivesToAllGraphQLScalarTypes(pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): Pair<PrimitiveType,String>[*]
function meta::external::query::graphQL::binding::purePrimitivesToCustomGraphQLScalarTypes(): Pair<PrimitiveType,String>[*]
{
[
pair(Integer, if($pureTypeToGraphQLScalarOverride->isEmpty() || $pureTypeToGraphQLScalarOverride->toOne().integerScalarType->isEmpty(), | 'Int', | $pureTypeToGraphQLScalarOverride->toOne().integerScalarType->toOne())),
pair(String, 'String'),
pair(Float, 'Float'),
pair(Boolean, 'Boolean'),
pair(Date, 'Date'),
pair(StrictDate, 'StrictDate'),
pair(DateTime, 'DateTime'),
pair(Decimal, 'BigDecimal')
]
}

function meta::external::query::graphQL::binding::builtInGraphQLScalars(): String[*]
{
['Int', 'Float', 'String', 'Boolean', 'ID'];
}

function meta::external::query::graphQL::binding::purePrimitivesToCustomGraphQLScalarTypes(pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): Pair<PrimitiveType,String>[*]
{
purePrimitivesToAllGraphQLScalarTypes($pureTypeToGraphQLScalarOverride)
// remove built in GraphQL Scalars
->filter(p | !$p.second->in(builtInGraphQLScalars()))
}

// Inversion of the pure primitives to graphQL with some extras
function meta::external::query::graphQL::binding::graphQLScalarTypesToPurePrimitives(pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): Pair<String,PrimitiveType>[*]
// Concat and invert the pure primitives to graphQL
function meta::external::query::graphQL::binding::graphQLScalarTypesToPurePrimitives(): Pair<String,PrimitiveType>[*]
{
if($pureTypeToGraphQLScalarOverride->isEmpty() || $pureTypeToGraphQLScalarOverride->toOne().integerScalarType->isEmpty(), | [], | [pair($pureTypeToGraphQLScalarOverride->toOne().integerScalarType->toOne(), Integer)])
->concatenate(
[
// Keep all default mappings as well
pair('String', String),
pair('Int', Integer),
pair('Float', Float),
pair('Boolean', Boolean),
pair('Date', Date),
pair('StrictDate', StrictDate),
pair('DateTime', DateTime),
pair('BigDecimal', Decimal),
pair('ID', String)
]
)
purePrimitivesToGraphQLScalarTypes()->concatenate(purePrimitivesToCustomGraphQLScalarTypes())
->map(p | pair($p.second, $p.first))
->concatenate(pair('ID', String))
}

function meta::external::query::graphQL::binding::temporalityToDirectives(): Map<String,DirectiveDefinition>[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Class meta::external::query::graphQL::metamodel::sdl::GraphQLSDLContainer

Class meta::external::query::graphQL::binding::fromPure::sdl::ModelToGraphQLConfig extends meta::external::format::shared::transformation::fromPure::ModelToSchemaConfiguration
{
pureTypeToGraphQLScalarOverride: meta::external::query::graphQL::binding::PureTypeToGraphQLScalarOverride[0..1];
}

function meta::external::query::graphQL::binding::fromPure::sdl::pureToGraphQLSDL(modelUnit: ModelUnit[1], config: ModelToGraphQLConfig[1]): meta::external::format::shared::metamodel::SchemaSet[1]
Expand All @@ -22,7 +21,7 @@ function meta::external::query::graphQL::binding::fromPure::sdl::pureToGraphQLSD
let document =
^meta::external::query::graphQL::metamodel::sdl::Document
(
definitions = meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL($packageableElements, $config)
definitions = meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL($packageableElements)
);
let sdlcContainer =
^meta::external::query::graphQL::metamodel::sdl::GraphQLSDLContainer
Expand Down Expand Up @@ -55,10 +54,9 @@ function meta::external::query::graphQL::binding::fromPure::sdl::schemaDetailToS
->joinStrings('\n');
}

function meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL(types: meta::pure::metamodel::PackageableElement[*], config: ModelToGraphQLConfig[1]): meta::external::query::graphQL::metamodel::sdl::typeSystem::TypeSystemDefinition[*]
function meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL(types: meta::pure::metamodel::PackageableElement[*]): meta::external::query::graphQL::metamodel::sdl::typeSystem::TypeSystemDefinition[*]
{
let allTypes = $types->findTypes();
let pureTypeToGraphQLScalarOverride = $config.pureTypeToGraphQLScalarOverride;

let queryClasses = $allTypes->cast(@AnnotatedElement)->filter(t|$t.stereotypes.value->contains('Query'))->cast(@Class<Any>);
let mutationClasses = $allTypes->cast(@AnnotatedElement)->filter(t|$t.stereotypes.value->contains('Mutation'))->cast(@Class<Any>);
Expand Down Expand Up @@ -104,16 +102,16 @@ function meta::external::query::graphQL::binding::fromPure::sdl::transformPureTo
c:Class<Any>[1] |
if ($classInputTypes->contains($c),
|
buildInputObjectTypeDefinition($c, $pureTypeToGraphQLScalarOverride)->concatenate(
buildInputObjectTypeDefinition($c)->concatenate(
if ($classReturnTypes->contains($c),
// Used as both -> needs both input and output types
| buildObjectTypeDefinition($c, $extendedClasses->contains($c), $pureTypeToGraphQLScalarOverride),
| buildObjectTypeDefinition($c, $extendedClasses->contains($c)),
// Used as input -> needs input
| []
)
),
// Not used as input --> needs output (unused types will result in output types)
| buildObjectTypeDefinition($c, $extendedClasses->contains($c), $pureTypeToGraphQLScalarOverride)
| buildObjectTypeDefinition($c, $extendedClasses->contains($c))
),
e:Enumeration<Any>[1] |
^EnumTypeDefinition(
Expand All @@ -135,7 +133,7 @@ function meta::external::query::graphQL::binding::fromPure::sdl::transformPureTo
->distinct()
->map(s | temporalityToDirectives()->get($s)->toOne());

let interfaces = $extendedClasses->map(c | $c->buildInterfaceTypeDefinition($pureTypeToGraphQLScalarOverride));
let interfaces = $extendedClasses->map(c | $c->buildInterfaceTypeDefinition());

$partitioned.second.values
// Remove duplicated scalar definitions
Expand Down Expand Up @@ -180,23 +178,23 @@ function <<access.private>> meta::external::query::graphQL::binding::fromPure::s
!$p.name->in(['processingDate', 'businessDate', 'milestoning']);
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildNonBuiltInGraphQLScalars(props: AbstractProperty<Any>[*], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): ScalarTypeDefinition[*]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildNonBuiltInGraphQLScalars(props: AbstractProperty<Any>[*]): ScalarTypeDefinition[*]
{
$props
->map(p | $p.genericType.rawType->toOne())
->map(p | $p->match(
[
p : PrimitiveType[1] | purePrimitivesToCustomGraphQLScalarTypes($pureTypeToGraphQLScalarOverride)->newMap()->get($p),
p : PrimitiveType[1] | purePrimitivesToCustomGraphQLScalarTypes()->newMap()->get($p),
a : Any[1] | []
]
))
->map(customScalar | ^ScalarTypeDefinition(name = $customScalar))
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInputObjectTypeDefinition(c: Class<Any>[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeSystemDefinition[*]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInputObjectTypeDefinition(c: Class<Any>[1]): TypeSystemDefinition[*]
{
let props = $c->hierarchicalAllProperties()->filter(p | $p->isValidPropertyForGraphQL());
let nonBuiltInScalars = $props->buildNonBuiltInGraphQLScalars($pureTypeToGraphQLScalarOverride);
let nonBuiltInScalars = $props->buildNonBuiltInGraphQLScalars();

let temporalStereotypes = $c->getTemporalStereotypes();
$nonBuiltInScalars
Expand All @@ -209,15 +207,15 @@ function <<access.private>> meta::external::query::graphQL::binding::fromPure::s
^InputValueDefinition
(
name = $p.name->toOne(),
type = buildInputTypeCompatibleTypeReference($p.genericType, $p.multiplicity, $pureTypeToGraphQLScalarOverride)
type = buildInputTypeCompatibleTypeReference($p.genericType, $p.multiplicity)
))
));
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildObjectTypeDefinition(c: Class<Any>[1], isExtended: Boolean[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeSystemDefinition[*]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildObjectTypeDefinition(c: Class<Any>[1], isExtended: Boolean[1]): TypeSystemDefinition[*]
{
let props = $c->hierarchicalAllProperties()->filter(p | $p->isValidPropertyForGraphQL());
let nonBuiltInScalars = $props->buildNonBuiltInGraphQLScalars($pureTypeToGraphQLScalarOverride);
let nonBuiltInScalars = $props->buildNonBuiltInGraphQLScalars();

let temporalStereotypes = $c->getTemporalStereotypes();
$nonBuiltInScalars
Expand All @@ -231,15 +229,15 @@ function <<access.private>> meta::external::query::graphQL::binding::fromPure::s
^FieldDefinition
(
name = $p.name->toOne(),
type = buildObjectTypeCompatibleTypeReference($p->functionReturnType(), $p->functionReturnMultiplicity(), $pureTypeToGraphQLScalarOverride),
type = buildObjectTypeCompatibleTypeReference($p->functionReturnType(), $p->functionReturnMultiplicity()),
argumentDefinitions =
if ($p->instanceOf(QualifiedProperty),
|
$p->functionType().parameters->evaluateAndDeactivate()->tail()->map(pa |
^InputValueDefinition
(
name = $pa.name,
type = buildInputTypeCompatibleTypeReference($pa.genericType, $pa.multiplicity, $pureTypeToGraphQLScalarOverride)
type = buildInputTypeCompatibleTypeReference($pa.genericType, $pa.multiplicity)
)
),
|
Expand All @@ -250,7 +248,7 @@ function <<access.private>> meta::external::query::graphQL::binding::fromPure::s
));
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInterfaceTypeDefinition(c: Class<Any>[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeSystemDefinition[*]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInterfaceTypeDefinition(c: Class<Any>[1]): TypeSystemDefinition[*]
{
let props = $c->hierarchicalAllProperties()->filter(p | $p->isValidPropertyForGraphQL());

Expand All @@ -264,32 +262,32 @@ function <<access.private>> meta::external::query::graphQL::binding::fromPure::s
^FieldDefinition
(
name = $p.name->toOne(),
type = buildObjectTypeCompatibleTypeReference($p->functionReturnType(), $p->functionReturnMultiplicity(), $pureTypeToGraphQLScalarOverride),
type = buildObjectTypeCompatibleTypeReference($p->functionReturnType(), $p->functionReturnMultiplicity()),
argumentDefinitions = []
)
)
);
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildObjectTypeCompatibleTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeReference[1]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildObjectTypeCompatibleTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1]): TypeReference[1]
{
buildTypeReference($type, $mul, false, $pureTypeToGraphQLScalarOverride)
buildTypeReference($type, $mul, false)
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInputTypeCompatibleTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeReference[1]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildInputTypeCompatibleTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1]): TypeReference[1]
{
buildTypeReference($type, $mul, true, $pureTypeToGraphQLScalarOverride)
buildTypeReference($type, $mul, true)
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1], forInput: Boolean[1], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): TypeReference[1]
function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::buildTypeReference(type:meta::pure::metamodel::type::generics::GenericType[1], mul:Multiplicity[1], forInput: Boolean[1]): TypeReference[1]
{
let typeName =
if ($type.rawType->toOne()->instanceOf(Class) && $forInput,
|
// Must create reference to input type
toInputTypeName($type.rawType.name->toOne()),
|
let primitives = purePrimitivesToAllGraphQLScalarTypes($pureTypeToGraphQLScalarOverride)->newMap();
let primitives = purePrimitivesToGraphQLScalarTypes()->concatenate(purePrimitivesToCustomGraphQLScalarTypes())->newMap();
let foundPrimitiveName = $primitives->get($type.rawType->toOne());
let fName = if($foundPrimitiveName->isEmpty(), | $type.rawType.name,| $foundPrimitiveName->toOne());
)->toOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,33 +189,6 @@ function <<test.Test>> meta::external::query::graphQL::binding::fromPure::sdl::t
'scalar StrictDate', $res);
}

function <<test.Test>> meta::external::query::graphQL::binding::fromPure::sdl::tests::testNonBuiltInPrimitiveTypesWithLongForInteger():Boolean[1]
{
let res = typesToGraphQLString([ClassWithPrimitiveTypes], ^PureTypeToGraphQLScalarOverride(integerScalarType = 'Long'));

assertEquals(
'scalar BigDecimal\n' +
'\n' +
'type ClassWithPrimitiveTypes {\n' +
' string: String!\n' +
' integer: Long!\n' +
' float: Float!\n' +
' boolean: Boolean!\n' +
' date: Date!\n' +
' datetime: DateTime!\n' +
' decimal: BigDecimal!\n' +
' strictDate: StrictDate!\n' +
'}\n' +
'\n' +
'scalar Date\n' +
'\n' +
'scalar DateTime\n' +
'\n' +
'scalar Long\n' +
'\n' +
'scalar StrictDate', $res);
}

function <<test.Test>> meta::external::query::graphQL::binding::fromPure::sdl::tests::testNonBuiltInPrimitiveTypesAreNotDuplicated():Boolean[1]
{
let res = typesToGraphQLString([ClassWithPrimitiveTypes, MutationPrimitive]);
Expand Down Expand Up @@ -460,14 +433,7 @@ function <<test.Test>> meta::external::query::graphQL::binding::fromPure::sdl::t

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::tests::typesToGraphQLString(types: PackageableElement[*]): String[1]
{
typesToGraphQLString($types, []);
}

function <<access.private>> meta::external::query::graphQL::binding::fromPure::sdl::tests::typesToGraphQLString(types: PackageableElement[*], pureTypeToGraphQLScalarOverride: PureTypeToGraphQLScalarOverride[0..1]): String[1]
{
let defaultConfig = meta::external::query::graphQL::binding::fromPure::sdl::defaultConfig();
let updatedConfig = ^$defaultConfig(pureTypeToGraphQLScalarOverride = $pureTypeToGraphQLScalarOverride);
meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL($types, $updatedConfig)
meta::external::query::graphQL::binding::fromPure::sdl::transformPureToGraphQLSDL($types)
->map(x|$x->meta::external::query::graphQL::serialization::graphQLtoString())
->joinStrings('\n\n');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function meta::external::query::graphQL::binding::toPure::introspection::buildPu
{
let pack = meta::external::query::graphQL::binding::toPure::buildTransientPackageFromString($package);

let simpleTypes = meta::external::query::graphQL::binding::graphQLScalarTypesToPurePrimitives([])->newMap();
let simpleTypes = meta::external::query::graphQL::binding::graphQLScalarTypesToPurePrimitives()->newMap();

let dispatch = [
pair(__TypeKind.OBJECT, t:__Type[1]| let no = newClass($t.name->toOne());
Expand Down
Loading

0 comments on commit 4ae864f

Please sign in to comment.