-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,7 @@ | ||
import "package:built_value/serializer.dart"; | ||
|
||
class DefaultScalarSerializer<T> implements PrimitiveSerializer<T> { | ||
final T Function(Object serialized) _deserialize; | ||
|
||
DefaultScalarSerializer(this._deserialize); | ||
|
||
@override | ||
final types = <Type>[T]; | ||
@override | ||
final wireName = T.toString(); | ||
|
||
@override | ||
Object serialize(Serializers serializers, T scalar, | ||
{FullType specifiedType = FullType.unspecified}) => | ||
(scalar as dynamic).value as Object; | ||
|
||
@override | ||
T deserialize(Serializers serializers, Object serialized, | ||
{FullType specifiedType = FullType.unspecified}) => | ||
_deserialize(serialized); | ||
} | ||
// serializers have been implemented in this files originally, | ||
// but moved to a separate package later to avoid | ||
// direct dependencies on gql_code_builder in application code. | ||
// This file is kept for backwards compatibility and should be removed in | ||
// the next major version of gql_code_builder. | ||
export "package:gql_code_builder_serializers/gql_code_builder_serializers.dart" | ||
show DefaultScalarSerializer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,7 @@ | ||
import "package:built_value/serializer.dart"; | ||
import "package:built_value/standard_json_plugin.dart"; | ||
|
||
/// Deserializes a GraphQL selection with inline fragments into it's | ||
/// appropriate concrete data class based on its `__typename` field. | ||
/// | ||
/// If no `__typename` is found, it will simply return a base data class that | ||
/// only includes the common fields. | ||
class InlineFragmentSerializer<T> implements StructuredSerializer<T> { | ||
final String rootName; | ||
final Type baseClass; | ||
final Map<String, Type> asTypeClasses; | ||
|
||
InlineFragmentSerializer( | ||
this.rootName, | ||
this.baseClass, | ||
this.asTypeClasses, | ||
); | ||
|
||
Type _typeForTypename(String name) => asTypeClasses[name] ?? baseClass; | ||
|
||
@override | ||
T deserialize( | ||
Serializers serializers, | ||
Iterable serialized, { | ||
FullType specifiedType = FullType.unspecified, | ||
}) { | ||
try { | ||
// Get JSON representation of object | ||
final json = StandardJsonPlugin() | ||
.afterSerialize(serialized, specifiedType) as Map<String, dynamic>; | ||
final typeName = (json["__typename"] ?? "") as String; | ||
final type = _typeForTypename(typeName); | ||
final serializer = | ||
serializers.serializerForType(type) as StructuredSerializer; | ||
return serializer.deserialize(serializers, serialized, | ||
specifiedType: specifiedType) as T; | ||
} catch (e) { | ||
rethrow; | ||
} | ||
} | ||
|
||
@override | ||
Iterable<Object?> serialize( | ||
Serializers serializers, | ||
T object, { | ||
FullType specifiedType = FullType.unspecified, | ||
}) { | ||
try { | ||
final typeName = (object as dynamic).G__typename as String; | ||
final type = _typeForTypename(typeName); | ||
final serializer = | ||
serializers.serializerForType(type) as StructuredSerializer; | ||
return serializer.serialize(serializers, object, | ||
specifiedType: specifiedType); | ||
} catch (e) { | ||
rethrow; | ||
} | ||
} | ||
|
||
@override | ||
Iterable<Type> get types => [T]; | ||
|
||
@override | ||
String get wireName => rootName; | ||
} | ||
// serializers have been implemented in this files originally, | ||
// but moved to a separate package later to avoid | ||
// direct dependencies on gql_code_builder in application code. | ||
// This file is kept for backwards compatibility and should be removed in | ||
// the next major version of gql_code_builder. | ||
export "package:gql_code_builder_serializers/gql_code_builder_serializers.dart" | ||
show InlineFragmentSerializer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
import "package:built_value/serializer.dart"; | ||
import "package:built_value/standard_json_plugin.dart"; | ||
|
||
/// A serializer which can be implemented to easily build a Json Serializer | ||
abstract class JsonSerializer<T> implements StructuredSerializer<T> { | ||
final _jsonPlugin = StandardJsonPlugin(); | ||
|
||
T fromJson(Map<String, dynamic> json); | ||
|
||
Map<String, dynamic> toJson(T object); | ||
|
||
@override | ||
T deserialize( | ||
Serializers serializers, | ||
Iterable serialized, { | ||
FullType specifiedType = FullType.unspecified, | ||
}) { | ||
final json = _jsonPlugin.afterSerialize(serialized, specifiedType) | ||
as Map<String, dynamic>; | ||
return fromJson(json); | ||
} | ||
|
||
@override | ||
Iterable<Object?> serialize( | ||
Serializers serializers, | ||
T object, { | ||
FullType specifiedType = FullType.unspecified, | ||
}) { | ||
final json = toJson(object); | ||
final serialized = _jsonPlugin.beforeDeserialize(json, FullType(T)); | ||
return serialized is Iterable ? serialized : [serialized]; | ||
} | ||
|
||
@override | ||
Iterable<Type> get types => [T]; | ||
|
||
@override | ||
String get wireName => T.toString(); | ||
} | ||
// serializers have been implemented in this files originally, | ||
// but moved to a separate package later to avoid | ||
// direct dependencies on gql_code_builder in application code. | ||
// This file is kept for backwards compatibility and should be removed in | ||
// the next major version of gql_code_builder. | ||
export "package:gql_code_builder_serializers/gql_code_builder_serializers.dart" | ||
show JsonSerializer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
import "package:gql/language.dart"; | ||
import "package:gql_exec/gql_exec.dart"; | ||
|
||
import "./json_serializer.dart"; | ||
|
||
class OperationSerializer extends JsonSerializer<Operation> { | ||
@override | ||
Operation fromJson(Map<String, dynamic> json) => Operation( | ||
document: parseString(json["document"] as String), | ||
operationName: json["operationName"] as String?, | ||
); | ||
|
||
@override | ||
Map<String, dynamic> toJson(Operation operation) => <String, dynamic>{ | ||
"document": printNode(operation.document), | ||
if (operation.operationName != null) | ||
"operationName": operation.operationName, | ||
}; | ||
} | ||
// serializers have been implemented in this files originally, | ||
// but moved to a separate package later to avoid | ||
// direct dependencies on gql_code_builder in application code. | ||
// This file is kept for backwards compatibility and should be removed in | ||
// the next major version of gql_code_builder. | ||
export "package:gql_code_builder_serializers/gql_code_builder_serializers.dart" | ||
show OperationSerializer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ |