-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2347 from graphcommerce-org/fix/dynamic-rows
Resolve issue where the dynamic rows UI wouldn’t load any definitions
- Loading branch information
Showing
10 changed files
with
127 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphcommerce/hygraph-dynamic-rows-ui": patch | ||
--- | ||
|
||
Resolve issue where the dynamic rows UI wouldn’t load any definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
packages/hygraph-dynamic-rows-ui/lib/createOptionsFromInterfaceObject.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/hygraph-dynamic-rows-ui/lib/createRecursiveIntrospectionQuery.ts
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
packages/hygraph-dynamic-rows-ui/lib/fetchGraphQLInterface.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { IntrospectionField, IntrospectionOutputTypeRef, IntrospectionSchema } from 'graphql' | ||
|
||
function getType(type: IntrospectionOutputTypeRef) { | ||
switch (type.kind) { | ||
case 'NON_NULL': | ||
case 'LIST': | ||
return getType(type.ofType) | ||
default: | ||
return type | ||
} | ||
} | ||
|
||
class FieldPath { | ||
constructor( | ||
public field: IntrospectionField, | ||
private prev: FieldPath | undefined, | ||
) {} | ||
|
||
stringify(filter?: string[]): string | undefined { | ||
if (this.field.type.kind === 'SCALAR' && filter && !filter.includes(this.field.type.name)) { | ||
return undefined | ||
} | ||
|
||
const prevStr = this.prev?.stringify(filter) | ||
return prevStr ? `${prevStr}.${this.field.name}` : this.field.name | ||
} | ||
|
||
depth = () => (this?.prev?.depth() ?? 0) + 1 | ||
} | ||
|
||
export function getFieldPaths( | ||
schema: IntrospectionSchema, | ||
types: string[], | ||
prevPath: FieldPath | undefined = undefined, | ||
): FieldPath[] { | ||
const typeName = types[types.length - 1] | ||
|
||
const paths: FieldPath[] = [] | ||
const type = schema.types.find((t) => t.name === typeName) | ||
|
||
if (!type) return paths | ||
|
||
if ((prevPath?.depth() ?? 0) > 3) return paths | ||
|
||
if (type.kind === 'OBJECT' || type.kind === 'INTERFACE') { | ||
type.fields.forEach((field) => { | ||
const t = getType(field.type) | ||
|
||
if (!types.includes(t.name) && !field.deprecationReason) { | ||
const newTypes = [...types, t.name] | ||
|
||
const newPath = new FieldPath(field, prevPath) | ||
|
||
if (t.kind === 'OBJECT' || t.kind === 'INTERFACE') { | ||
paths.push(...getFieldPaths(schema, newTypes, newPath)) | ||
} else if (t.kind === 'SCALAR' || t.kind === 'ENUM') { | ||
paths.push(newPath) | ||
} else if (t.kind === 'UNION') { | ||
// not supported currently | ||
} | ||
} | ||
}) | ||
} | ||
|
||
return paths | ||
} |
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
packages/hygraph-dynamic-rows-ui/lib/objectifyGraphQLInterface.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.