Skip to content

Fixed ID type deserialization #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/FSharp.Data.GraphQL.Client/BaseTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,19 @@ module internal JsonValueHelper =
| Some "Date" ->
match DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None) with
| (true, d) -> box d
| _ -> failwith "A string was received in the query response, and the schema recognizes it as a date and time sring, but the conversion failed."
| _ -> failwith "A string was received in the query response, and the schema recognizes it as a date and time string, but the conversion failed."
| _ -> failwith "A string type was received in the query response item, but the matching schema field is not a string based type."
| TypeKind.ENUM when itemType.Name.IsSome -> EnumBase(itemType.Name.Value, s) |> box
| _ -> failwith "A string type was received in the query response item, but the matching schema field is not a string or an enum type."
| None -> failwith "Item type is a non null type, but no underlying type exists on the schema definition of the type."
| TypeKind.SCALAR ->
match schemaField.SchemaTypeRef.Name with
| Some "String" -> makeSomeIfNeeded s
| Some "String" | Some "ID" -> makeSomeIfNeeded s
| Some "URI" -> System.Uri(s) |> makeSomeIfNeeded
| Some "Date" ->
match DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None) with
| (true, d) -> makeSomeIfNeeded d
| _ -> failwith "A string was received in the query response, and the schema recognizes it as a date and time sring, but the conversion failed."
| _ -> failwith "A string was received in the query response, and the schema recognizes it as a date and time string, but the conversion failed."
| _ -> failwith "A string type was received in the query response item, but the matching schema field is not a string based type."
| TypeKind.ENUM when schemaField.SchemaTypeRef.Name.IsSome -> EnumBase(schemaField.SchemaTypeRef.Name.Value, s) |> makeSomeIfNeeded
| _ -> failwith "A string type was received in the query response item, but the matching schema field is not a string based type or an enum type."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="NameValueLookupTests.fs" />
<Compile Include="SubscriptionTests.fs" />
<Compile Include="AstExtensionsTests.fs" />
<Compile Include="ResponseJsonTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -55,11 +56,12 @@
<ItemGroup>
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Shared\FSharp.Data.GraphQL.Shared.fsproj" />
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Server\FSharp.Data.GraphQL.Server.fsproj" />
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Client.DesignTime\FSharp.Data.GraphQL.Client.DesignTime.fsproj" />
<ProjectReference Include="..\..\src\FSharp.Data.GraphQL.Server.Middleware\FSharp.Data.GraphQL.Server.Middleware.fsproj" />
</ItemGroup>
<ItemGroup Condition="$(OS) == Unix">
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<Import Project="..\..\netfx.props" />
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
</Project>
73 changes: 73 additions & 0 deletions tests/FSharp.Data.GraphQL.Tests/ResponseJsonTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module FSharp.Data.GraphQL.Tests.ResponseJsonTests

open System
open Xunit
open Helpers
open FSharp.Data.GraphQL
open FSharp.Data.GraphQL.Client

// Local provider should be able to be created from local introspection json file.
// This schema is adjusted to have some less common type names in order to test them.
type Provider = GraphQLProvider<"introspection-altered-types.json">


[<Fact>]
let ``Should be able to parse nullable ID``() =
let op = Provider.Operation<"""query TestQuery {
hero(id:"1000") {
id,
name,
appearsIn,
homePlanet,
friends {
... on Human {
name,
id
}
... on Droid {
name,
id
}
}
}
}""">
let xop = op()
let result1 = xop.ParseResult("""{
"documentId": 2018203290,
"data": {
"hero": {
"id": "1000",
"__typename": "Human",
"name": "Luke Skywalker",
"appearsIn": [
"NewHope",
"Empire",
"Jedi"
],
"homePlanet": "Tatooine",
"friends": [
{
"name": "Han Solo",
"id": "1002",
"__typename": "Human"
},
{
"name": "Leia Organa",
"id": "1003",
"__typename": "Human"
},
{
"name": "C-3PO",
"id": "2000",
"__typename": "Droid"
},
{
"name": "R2-D2",
"id": "2001",
"__typename": "Droid"
}
]
}
}
}""")
()
Loading