Skip to content

Commit

Permalink
Fix bug in React framwork when hydrating scalars (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Mar 9, 2024
1 parent 7f426d9 commit 250ff78
Show file tree
Hide file tree
Showing 30 changed files with 644 additions and 613 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-dingos-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-react': patch
---

Fix bug marshaling/unmarshaling scalars over network
63 changes: 55 additions & 8 deletions e2e/_api/graphql.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,61 @@ let monkeys = [

// example data
const dataUsers = [
{ id: '1', name: 'Bruce Willis', birthDate: new Date(1955, 2, 19) },
{ id: '2', name: 'Samuel Jackson', birthDate: new Date(1948, 11, 21) },
{ id: '3', name: 'Morgan Freeman', birthDate: new Date(1937, 5, 0) },
{ id: '4', name: 'Tom Hanks', birthDate: new Date(1956, 6, 9) },
{ id: '5', name: 'Will Smith', birthDate: new Date(1968, 8, 25) },
{ id: '6', name: 'Harrison Ford', birthDate: new Date(1942, 6, 13) },
{ id: '7', name: 'Eddie Murphy', birthDate: new Date(1961, 3, 3) },
{ id: '8', name: 'Clint Eastwood', birthDate: new Date(1930, 5, 31) },
{
id: '1',
name: 'Bruce Willis',
birthDate: new Date(1955, 2, 19),
avatarURL:
'https://variety.com/wp-content/uploads/2022/03/Bruce-Willis.jpg?w=1000&h=562&crop=1',
},
{
id: '2',
name: 'Samuel Jackson',
birthDate: new Date(1948, 11, 21),
avatarURL: 'https://imaging.broadway.com/images/regular-43/w750/122004-11.jpeg',
},
{
id: '3',
name: 'Morgan Freeman',
birthDate: new Date(1937, 5, 0),
avatarURL:
'https://www.themoviedb.org/t/p/w600_and_h900_bestv2/jPsLqiYGSofU4s6BjrxnefMfabb.jpg',
},
{
id: '4',
name: 'Tom Hanks',
birthDate: new Date(1956, 6, 9),
avatarURL:
'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Tom_Hanks_TIFF_2019.jpg/440px-Tom_Hanks_TIFF_2019.jpg',
},
{
id: '5',
name: 'Will Smith',
birthDate: new Date(1968, 8, 25),
avatarURL:
'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/TechCrunch_Disrupt_2019_%2848834434641%29_%28cropped%29.jpg/440px-TechCrunch_Disrupt_2019_%2848834434641%29_%28cropped%29.jpg',
},
{
id: '6',
name: 'Harrison Ford',
birthDate: new Date(1942, 6, 13),
avatarURL:
'https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/Harrison_Ford_by_Gage_Skidmore_3.jpg/1280px-Harrison_Ford_by_Gage_Skidmore_3.jpg',
},
{
id: '7',
name: 'Eddie Murphy',
birthDate: new Date(1961, 3, 3),
avatarURL:
'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Eddie_Murphy_by_David_Shankbone.jpg/440px-Eddie_Murphy_by_David_Shankbone.jpg',
},
{
id: '8',
name: 'Clint Eastwood',
birthDate: new Date(1930, 5, 31),
avatarURL:
'https://prod-images.tcm.com/Master-Profile-Images/ClintEastwood.55386.jpg?w=824',
},
]

let dataRentedBooks = [
Expand Down
1 change: 1 addition & 0 deletions e2e/_api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type User implements Node {
enumValue: MyEnum
types: [TypeOfUser!]!
testField(someParam: Boolean!): String
avatarURL(size: Int): String!
}

interface Animal implements Node {
Expand Down
3 changes: 3 additions & 0 deletions e2e/react/houdini.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/// <references types="houdini-router">
/** @type {import('houdini').ConfigFile} */
const config = {
watchSchema: {
url: 'http://localhost:4000/graphql',
},
defaultPartial: true,
scalars: {
DateTime: {
Expand Down
5 changes: 4 additions & 1 deletion e2e/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"api": "cross-env TZ=utc e2e-api",
"build:": "cd ../../ && ((pnpm run build && cd -) || (cd - && exit 1))",
"build:dev": "pnpm build: && pnpm dev",
"build:web": "pnpm build: && pnpm web",
"build:test": "pnpm build: && pnpm test",
"build:generate": "pnpm build: && pnpm houdini generate",
"build:build": "pnpm build: && pnpm build",
"dev": "vite",
"web": "vite dev",
"dev": "concurrently \"pnpm run web\" \"pnpm run api\" -n \"web,api\" -c \"green,magenta\"",
"build": "vite build",
"tests": "playwright test ",
"test": "npm run tests",
Expand All @@ -24,6 +26,7 @@
"@pothos/plugin-simple-objects": "^3.7.0",
"@whatwg-node/server": "^0.9.14",
"cookie": "^0.5.0",
"e2e-api": "workspace:^",
"graphql-yoga": "^4.0.4",
"houdini": "workspace:^",
"houdini-adapter-cloudflare": "workspace:^",
Expand Down
189 changes: 189 additions & 0 deletions e2e/react/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
type A {
a: String!
id: ID!
}

interface Animal implements Node {
id: ID!
name: String!
}

interface AnimalConnection {
edges: [AnimalEdge!]!
pageInfo: PageInfo!
}

interface AnimalEdge {
cursor: String
node: Animal
}

type B {
b: String!
id: ID!
}

type Book {
id: ID!
title: String!
}

type City {
id: ID!
libraries: [Library]!
name: String!
}

"""Date custom scalar type"""
scalar DateTime

scalar File

enum ForceReturn {
ERROR
NORMAL
NULL
}

type Library {
books: [Book]!
id: ID!
name: String!
}

type Message1 {
message: String!
}

type Monkey implements Animal & Node {
hasBanana: Boolean!
id: ID!
name: String!
}

type MonkeyConnection implements AnimalConnection {
edges: [MonkeyEdge!]!
pageInfo: PageInfo!
}

type MonkeyEdge implements AnimalEdge {
cursor: String
node: Monkey
}

type Mutation {
addBook(library: ID!, title: String!): Book!
addCity(name: String!): City!
addLibrary(city: ID!, name: String!): Library!
addNonNullUser(birthDate: DateTime!, delay: Int, enumValue: MyEnum, force: ForceReturn, name: String!, snapshot: String!, types: [TypeOfUser!]): User!
addUser(birthDate: DateTime!, delay: Int, enumValue: MyEnum, force: ForceReturn, name: String!, snapshot: String!, types: [TypeOfUser!]): User
createA(a: String!): A!
createB(b: String!): B!
deleteBook(book: ID!, delay: Int, force: ForceReturn): Book
deleteCity(city: ID!): City!
deleteLibrary(library: ID!): Library!
multipleUpload(files: [File!]!): [String!]!
singleUpload(file: File!): String!
updateRentedBook(bookId: Int!, rate: Int!, userId: String!): RentedBook
updateUser(birthDate: DateTime, delay: Int, id: ID!, name: String, snapshot: String!): User!
}

enum MyEnum {
Value1
Value2
}

interface Node {
id: ID!
}

type PageInfo {
endCursor: String
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
}

type Query {
aOrB: [UnionAorB!]!
animals: AnimalConnection!
avgYearsBirthDate: Float!
cities: [City]!
city(delay: Int, id: ID!): City
hello: String
monkey(id: ID!): Monkey
monkeys: MonkeyConnection!
node(id: ID!): Node
rentedBooks: [RentedBook!]!
session: String
user(delay: Int, forceNullDate: Boolean, id: ID!, snapshot: String!, tmp: Boolean): User!
userNodes(limit: Int = 4, offset: Int, snapshot: String!): UserNodes!
userNodesResult(forceMessage: Boolean!, snapshot: String!): UserNodesResult!
userResult(forceMessage: Boolean!, id: ID!, snapshot: String!): UserResult!
userSearch(filter: UserNameFilter!, snapshot: String!): [User!]!
usersConnection(after: String, before: String, first: Int, last: Int, snapshot: String!): UserConnection!
usersList(limit: Int = 4, offset: Int, snapshot: String!): [User!]!
}

type RentedBook {
bookId: Int!
rate: Int!
userId: String!
}

type Subscription {
userUpdate(id: ID!, snapshot: String): User
}

enum TypeOfUser {
COOL
NICE
}

union UnionAorB = A | B

type User implements Node {
avatarURL(size: Int): String!
birthDate: DateTime
enumValue: MyEnum
friendsConnection(after: String, before: String, first: Int, last: Int): UserConnection!
friendsList(limit: Int, offset: Int): [User!]!
id: ID!
name: String!
testField(someParam: Boolean!): String
types: [TypeOfUser!]!

"""
This is the same list as what's used globally. its here to tests fragments
"""
userSearch(filter: UserNameFilter!, snapshot: String!): [User!]!

"""
This is the same list as what's used globally. its here to tests fragments
"""
usersConnection(after: String, before: String, first: Int, last: Int): UserConnection!
usersConnectionSnapshot(after: String, before: String, first: Int, last: Int, snapshot: String!): UserConnection!
}

type UserConnection {
edges: [UserEdge!]!
pageInfo: PageInfo!
}

type UserEdge {
cursor: String
node: User
}

input UserNameFilter {
name: String!
}

type UserNodes {
nodes: [User!]!
totalCount: Int
}

union UserNodesResult = Message1 | UserNodes

union UserResult = Message1 | User
4 changes: 3 additions & 1 deletion e2e/react/src/+client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { HoudiniClient } from '$houdini'

// Export the Houdini client
export default new HoudiniClient()
export default new HoudiniClient({
url: 'http://localhost:4000/graphql',
})
4 changes: 0 additions & 4 deletions e2e/react/src/api/+schema.ts

This file was deleted.

22 changes: 0 additions & 22 deletions e2e/react/src/api/builder.ts

This file was deleted.

Loading

0 comments on commit 250ff78

Please sign in to comment.