Skip to content
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

Imperative Cache API #748

Merged
merged 72 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
577c963
add schema manager
AlecAivazis Dec 7, 2022
afe8fc3
add public wrapper with instability warning
AlecAivazis Dec 7, 2022
875fe95
start on publicWrapper
AlecAivazis Dec 7, 2022
ba997a4
can read/write scalar values
AlecAivazis Dec 8, 2022
cdb8b63
can retrieve linked records
AlecAivazis Dec 8, 2022
099bd43
can set linked records
AlecAivazis Dec 8, 2022
146f0b5
fix schema manager test
AlecAivazis Dec 8, 2022
dbaee34
validate idFields
AlecAivazis Dec 9, 2022
4220fa8
add schema manager
AlecAivazis Dec 7, 2022
f4f4d8e
add public wrapper with instability warning
AlecAivazis Dec 7, 2022
3983fb1
start on publicWrapper
AlecAivazis Dec 7, 2022
f8cdef5
can read/write scalar values
AlecAivazis Dec 8, 2022
a29ebbc
can retrieve linked records
AlecAivazis Dec 8, 2022
de16967
can set linked records
AlecAivazis Dec 8, 2022
42a3b16
fix schema manager test
AlecAivazis Dec 8, 2022
4fbe508
validate idFields
AlecAivazis Dec 9, 2022
ce6ec65
accomodate new selection structure
AlecAivazis Dec 9, 2022
69536ca
updated public api to new selection structure
AlecAivazis Dec 9, 2022
9a2ecb8
imperative api data is garbage collected like normal
AlecAivazis Dec 9, 2022
00e06e4
add back instability acknowlgement
AlecAivazis Dec 9, 2022
abf0670
rename test file
AlecAivazis Dec 9, 2022
27bedd8
changeset
AlecAivazis Dec 9, 2022
7c891d1
cache proxy can take a type definition for the schema
AlecAivazis Dec 10, 2022
d5a5f7a
fix tests
AlecAivazis Dec 10, 2022
5c1095c
embed args in cache description
AlecAivazis Dec 10, 2022
b2371bc
use correct type for args
AlecAivazis Dec 10, 2022
e55e421
split pubic api into multiple files
AlecAivazis Dec 10, 2022
46cfe36
merge
AlecAivazis Dec 10, 2022
abf7467
remove unused file
AlecAivazis Dec 10, 2022
90d46d1
clean up types
AlecAivazis Dec 11, 2022
37cef3f
typedefs for lists and abstract types
AlecAivazis Dec 12, 2022
f49d9e2
tests for writing lists and unions pass
AlecAivazis Dec 12, 2022
3fbc7c6
unused imports
AlecAivazis Dec 12, 2022
808a74a
fix comments
AlecAivazis Dec 12, 2022
d427a00
remove Proxy from names
AlecAivazis Dec 12, 2022
c6e2bd6
add public List
AlecAivazis Dec 13, 2022
f4fddba
add when to list api
AlecAivazis Dec 13, 2022
d3039c0
add remove to list
AlecAivazis Dec 13, 2022
e275e7b
remove placeholder tests
AlecAivazis Dec 13, 2022
af37277
add list.toggle
AlecAivazis Dec 13, 2022
9df6868
add method to delete record
AlecAivazis Dec 13, 2022
1e46a47
strengthen test
AlecAivazis Dec 13, 2022
6ca10a4
first pass at generating type defs
AlecAivazis Dec 13, 2022
7840ca6
better nullability behavior
AlecAivazis Dec 13, 2022
f38cba3
more better null handling
AlecAivazis Dec 13, 2022
05af1f8
fake tests
AlecAivazis Dec 13, 2022
075b3c5
use enum types
AlecAivazis Dec 13, 2022
4acb817
unused import
AlecAivazis Dec 13, 2022
91eb65d
rename listwhen to filters
AlecAivazis Dec 13, 2022
47d2b73
Merge branch 'main' into imperative-api
AlecAivazis Dec 13, 2022
8bd018e
start on args
AlecAivazis Dec 14, 2022
ceaba7a
arg definitions can reference input types
AlecAivazis Dec 14, 2022
735946d
support scalar lists
AlecAivazis Dec 14, 2022
b65eb3e
generated cache typedefitions use Records directly
AlecAivazis Dec 15, 2022
7430322
fix typedefs
AlecAivazis Dec 15, 2022
1e420c2
start on keys
AlecAivazis Dec 15, 2022
40975e4
add another todo test
AlecAivazis Dec 15, 2022
a2ed189
Merge branch 'main' into imperative-api
AlecAivazis Dec 16, 2022
84816f8
compute complex keys
AlecAivazis Dec 16, 2022
8e13166
better test for complex keys
AlecAivazis Dec 16, 2022
cc5f53b
fix invalid imports
AlecAivazis Dec 16, 2022
6690286
can write and retrieve nested nullable lists
AlecAivazis Dec 16, 2022
fc7dd0f
test for embedded data
AlecAivazis Dec 16, 2022
1ecb71f
generate list filters
AlecAivazis Dec 16, 2022
a5b4f4c
import Record from correct file
AlecAivazis Dec 16, 2022
94f9c0f
avoid duplicate processing of lists
AlecAivazis Dec 16, 2022
42353fb
fix nullability of fields args
AlecAivazis Dec 16, 2022
ee5ec92
comment
AlecAivazis Dec 16, 2022
1e23865
merge
AlecAivazis Dec 16, 2022
46be4fb
list act as proxies, not wrappers
AlecAivazis Dec 17, 2022
9e24857
iterating over an empty list behaves correctly
AlecAivazis Dec 17, 2022
947e848
remove unused import
AlecAivazis Dec 17, 2022
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
5 changes: 5 additions & 0 deletions .changeset/selfish-islands-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Add experimental imperative api for cache
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"graphql": "^15.8.0",
"prettier": "^2.7.0",
"turbo": "^1.5.5",
"typescript": "^4.9",
"vite": "^4.0.1",
"vitest": "^0.23.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,7 @@ describe('mutation artifacts', function () {
fields: {
users: {
type: "User",
keyRaw: "users(stringValue: $value, boolValue: true, floatValue: 1.2, intValue: 1)",
keyRaw: "users(boolValue: true, floatValue: 1.2, intValue: 1, stringValue: $value)",

list: {
name: "All_Users",
Expand Down Expand Up @@ -3522,7 +3522,7 @@ describe('mutation artifacts', function () {
fields: {
users: {
type: "User",
keyRaw: "users(stringValue: $value, boolValue: true, floatValue: 1.2, intValue: 1)",
keyRaw: "users(boolValue: true, floatValue: 1.2, intValue: 1, stringValue: $value)",

list: {
name: "All_Users",
Expand Down Expand Up @@ -3627,7 +3627,7 @@ describe('mutation artifacts', function () {
fields: {
users: {
type: "User",
keyRaw: "users(stringValue: $value, boolValue: true, floatValue: 1.2, intValue: 1)",
keyRaw: "users(boolValue: true, floatValue: 1.2, intValue: 1, stringValue: $value)",

list: {
name: "All_Users",
Expand Down Expand Up @@ -3851,7 +3851,7 @@ test('operation inputs', async function () {
fields: {
user: {
type: "User",
keyRaw: "user(id: $id, filter: $filter, filterList: $filterList, enumArg: $enumArg)",
keyRaw: "user(enumArg: $enumArg, filter: $filter, filterList: $filterList, id: $id)",
nullable: true,

selection: {
Expand Down
7 changes: 4 additions & 3 deletions packages/houdini/src/codegen/generators/artifacts/fieldKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export default function fieldKey(config: Config, field: graphql.FieldNode): stri
}
}, {})

const args = Object.keys(argObj)
args.sort()

let key =
Object.values(argObj).length > 0
? `${attributeName}(${Object.entries(argObj)
.map((entries) => entries.join(': '))
.join(', ')})`
? `${attributeName}(${args.map((key) => `${key}: ${argObj[key]}`).join(', ')})`
: attributeName

// if the field is paginated, key it differently so other documents can ask for the non paginated value without conflict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function operationObject({
operationWhen[i ? 'must_not' : 'must'] = arg.value.fields.reduce(
(obj, arg) => ({
...obj,
[arg.name.value]: convertValue(arg.value).value,
[arg.name.value]: convertValue(config, arg.value).value,
}),
{}
)
Expand All @@ -203,7 +203,7 @@ function operationObject({
operationWhen[which] = directive.arguments?.reduce(
(filters, argument) => ({
...filters,
[argument.name.value]: convertValue(argument.value).value,
[argument.name.value]: convertValue(config, argument.value).value,
}),
{}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ test("sibling aliases don't get marked", async function () {

friends: {
type: "UserConnection",
keyRaw: "friends(first: 10, filter: \\"hello\\")",
keyRaw: "friends(filter: \\"hello\\", first: 10)",

selection: {
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default function selection({
fieldObj.filters = (field.arguments || []).reduce(
(filters, arg) => ({
...filters,
[arg.name.value]: convertValue(arg.value),
[arg.name.value]: convertValue(config, arg.value),
}),
{}
)
Expand Down
6 changes: 3 additions & 3 deletions packages/houdini/src/codegen/generators/artifacts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ExpressionKind } from 'ast-types/lib/gen/kinds'
import * as graphql from 'graphql'
import * as recast from 'recast'

import { HoudiniError } from '../../../lib'
import { Config, HoudiniError } from '../../../lib'

const AST = recast.types.builders

Expand Down Expand Up @@ -81,12 +81,12 @@ export function deepMerge(filepath: string, ...targets: {}[]): {} {
)
}

export function convertValue(val: graphql.ValueNode) {
export function convertValue(config: Config, val: graphql.ValueNode) {
// figure out the value to use
let value
let kind

// the value of the arg is always going to be a
// the value of the arg is always going to be a scalar
if (val.kind === graphql.Kind.INT) {
value = parseInt(val.value, 10)
kind = 'Int'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function addReferencedInputTypes(
body: StatementKind[],
visitedTypes: Set<string>,
missingScalars: Set<string>,
rootType: graphql.TypeNode
rootType: graphql.TypeNode | graphql.GraphQLInputType
) {
// try to find the name of the type
const { type } = unwrapType(config, rootType)
Expand Down
Loading