Skip to content

Commit

Permalink
Make work again
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder committed May 2, 2023
1 parent f46b727 commit 15c0e11
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 57 deletions.
87 changes: 44 additions & 43 deletions packages/fields-document/src/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,47 @@ export const structure =

const defaultValue = getInitialPropsValue(schema);
const unreferencedConcreteInterfaceImplementations: graphql.ObjectType<any>[] = [];
if (!globalStructureTypes[name]) {
globalStructureTypes[name] = {
output: graphql.object<{ value: JSONValue }>()({
name: `${name}Output`,
fields: {
structure: getOutputGraphQLField(
name,
schema,
unreferencedConcreteInterfaceImplementations,
new Map(),
meta
),
json: graphql.field({
type: graphql.JSON,
args: {
hydrateRelationships: graphql.arg({
type: graphql.nonNull(graphql.Boolean),
defaultValue: false,
}),
},
resolve({ value }, args, context) {
if (args.hydrateRelationships) {
return addRelationshipDataToComponentProps(schema, value, (schema, value) =>
fetchRelationshipData(
context,
schema.listKey,
schema.many,
schema.selection || '',
value
)
);
}
return value;
},
}),
},
}),
update: getGraphQLInputType(name, schema, 'update', new Map(), meta),
create: getGraphQLInputType(name, schema, 'create', new Map(), meta),
};
const graphqlTypes = globalStructureTypes[name] || {
output: graphql.object<{ value: JSONValue }>()({
name: `${name}Output`,
fields: {
structure: getOutputGraphQLField(
name,
schema,
unreferencedConcreteInterfaceImplementations,
new Map(),
meta
),
json: graphql.field({
type: graphql.JSON,
args: {
hydrateRelationships: graphql.arg({
type: graphql.nonNull(graphql.Boolean),
defaultValue: false,
}),
},
resolve({ value }, args, context) {
if (args.hydrateRelationships) {
return addRelationshipDataToComponentProps(schema, value, (schema, value) =>
fetchRelationshipData(
context,
schema.listKey,
schema.many,
schema.selection || '',
value
)
);
}
return value;
},
}),
},
}),
update: getGraphQLInputType(name, schema, 'update', new Map(), meta),
create: getGraphQLInputType(name, schema, 'create', new Map(), meta),
};
if (config.graphql?.typeName) {
globalStructureTypes[name] = graphqlTypes;
}

return jsonFieldTypePolyfilledForSQLite(
Expand Down Expand Up @@ -125,20 +126,20 @@ export const structure =
input: {
create: {
arg: graphql.arg({
type: globalStructureTypes[name].create,
type: graphqlTypes.create,
}),
async resolve(val, context) {
return await getValueForCreate(schema, val, context, []);
},
},
update: {
arg: graphql.arg({
type: globalStructureTypes[name].update,
type: graphqlTypes.update,
}),
},
},
output: graphql.field({
type: globalStructureTypes[name].output,
type: graphqlTypes.output,
resolve(source) {
return source;
},
Expand Down
24 changes: 11 additions & 13 deletions tests/sandbox/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ type Thing {
text: String
timestamp: DateTime
structure: ThingStructureOutput
structureRelationships: ThingStructureRelationshipsOutput
structureNested: StructureNestedOutput
structureNested2: StructureNestedOutput
structureRelationships: ThingStructureRelationshipsOutput
checkbox: Boolean
password: PasswordState
toOneRelationship: User
Expand Down Expand Up @@ -46,8 +46,8 @@ type ThingStructure {
array: [Int]
}

type ThingStructureNestedOutput {
structure: [ThingStructureNested]
type StructureNestedOutput {
structure: [StructureNested]
json(hydrateRelationships: Boolean! = false): JSON
}

Expand Down Expand Up @@ -303,10 +303,9 @@ input ThingUpdateInput {
text: String
timestamp: DateTime
structure: ThingStructureUpdateInput
structureNested: [ThingStructureNestedUpdateInput]
structureRelationships: [ThingRelateToOneForUpdateInput]
structureNested: [StructureNestedUpdateInput]
structureNested2: [StructureNestedUpdateInput]
structureRelationships: [ThingRelateToOneForUpdateInput]
checkbox: Boolean
password: String
toOneRelationship: UserRelateToOneForUpdateInput
Expand Down Expand Up @@ -334,9 +333,9 @@ input ThingStructureUpdateInput {
array: [Int]
}

input ThingStructureNestedUpdateInput {
leaf: ThingStructureNestedLeafUpdateInput
group: ThingStructureNestedGroupUpdateInput
input StructureNestedUpdateInput {
leaf: StructureNestedLeafUpdateInput
group: StructureNestedGroupUpdateInput
}

input StructureNestedLeafUpdateInput {
Expand Down Expand Up @@ -388,10 +387,9 @@ input ThingCreateInput {
text: String
timestamp: DateTime
structure: ThingStructureCreateInput
structureNested: [ThingStructureNestedCreateInput]
structureRelationships: [ThingRelateToOneForCreateInput]
structureNested: [StructureNestedCreateInput]
structureNested2: [StructureNestedCreateInput]
structureRelationships: [ThingRelateToOneForCreateInput]
checkbox: Boolean
password: String
toOneRelationship: UserRelateToOneForCreateInput
Expand Down Expand Up @@ -419,9 +417,9 @@ input ThingStructureCreateInput {
array: [Int]
}

input ThingStructureNestedCreateInput {
leaf: ThingStructureNestedLeafCreateInput
group: ThingStructureNestedGroupCreateInput
input StructureNestedCreateInput {
leaf: StructureNestedLeafCreateInput
group: StructureNestedGroupCreateInput
}

input StructureNestedLeafCreateInput {
Expand Down
2 changes: 1 addition & 1 deletion tests/sandbox/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ model Thing {
timestamp DateTime?
structure String @default("{\"integer\":0,\"array\":[]}")
structureNested String @default("[]")
structureRelationships String @default("[]")
structureNested2 String @default("[]")
structureRelationships String @default("[]")
checkbox Boolean @default(false)
password String?
toOneRelationship User? @relation("Thing_toOneRelationship", fields: [toOneRelationshipId], references: [id])
Expand Down

0 comments on commit 15c0e11

Please sign in to comment.