fix: cascade graphql locales through relationships (#6166)
This commit is contained in:
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@@ -58,6 +58,13 @@
|
||||
"PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER": "s3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "node --no-deprecation test/dev.js collections-graphql",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"name": "Run Dev GraphQL",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
},
|
||||
{
|
||||
"command": "node --no-deprecation test/dev.js fields",
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
||||
@@ -28,6 +28,7 @@ export default function countResolver(collection: Collection): Resolver {
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
collection,
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function getDeleteResolver<TSlug extends keyof GeneratedTypes['co
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
id: args.id,
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function duplicateResolver<T extends keyof GeneratedTypes['collec
|
||||
const fallbackLocale = req.fallbackLocale
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
id: args.id,
|
||||
|
||||
@@ -34,6 +34,7 @@ export default function findResolver(collection: Collection): Resolver {
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
collection,
|
||||
|
||||
@@ -31,6 +31,7 @@ export default function findByIDResolver<T extends keyof GeneratedTypes['collect
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
id: args.id,
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function findVersionByIDResolver(collection: Collection): Resolve
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
id: args.id,
|
||||
|
||||
@@ -31,6 +31,7 @@ export default function findVersionsResolver(collection: Collection): Resolver {
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
collection,
|
||||
|
||||
@@ -32,6 +32,7 @@ export default function updateResolver<TSlug extends keyof GeneratedTypes['colle
|
||||
req = isolateObjectProperty(req, 'fallbackLocale')
|
||||
req.locale = args.locale || locale
|
||||
req.fallbackLocale = args.fallbackLocale || fallbackLocale
|
||||
context.req = req
|
||||
|
||||
const options = {
|
||||
id: args.id,
|
||||
|
||||
@@ -36,6 +36,10 @@ export const pointSlug = 'point'
|
||||
export const errorOnHookSlug = 'error-on-hooks'
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
localization: {
|
||||
defaultLocale: 'en',
|
||||
locales: ['en', 'es'],
|
||||
},
|
||||
collections: [
|
||||
{
|
||||
access: openAccess,
|
||||
@@ -333,6 +337,22 @@ export default buildConfigWithDefaults({
|
||||
],
|
||||
slug: 'content-type',
|
||||
},
|
||||
{
|
||||
slug: 'cyclical-relationship',
|
||||
access: openAccess,
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'relationToSelf',
|
||||
type: 'relationship',
|
||||
relationTo: 'cyclical-relationship',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
graphQL: {
|
||||
queries: (GraphQL) => {
|
||||
|
||||
@@ -960,6 +960,44 @@ describe('collections-graphql', () => {
|
||||
|
||||
expect(docs[0].relationHasManyField).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should query relationships with locale', async () => {
|
||||
const newDoc = await payload.create({
|
||||
collection: 'cyclical-relationship',
|
||||
data: {
|
||||
title: {
|
||||
en: 'English title',
|
||||
es: 'Spanish title',
|
||||
},
|
||||
},
|
||||
locale: '*',
|
||||
})
|
||||
|
||||
await payload.update({
|
||||
collection: 'cyclical-relationship',
|
||||
id: newDoc.id,
|
||||
data: {
|
||||
relationToSelf: newDoc.id,
|
||||
},
|
||||
})
|
||||
|
||||
const query = `query {
|
||||
CyclicalRelationships(locale: es) {
|
||||
docs {
|
||||
title
|
||||
relationToSelf {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
const res = await restClient
|
||||
.GRAPHQL_POST({ body: JSON.stringify({ query }) })
|
||||
.then((res) => res.json())
|
||||
|
||||
const queriedDoc = res.data.CyclicalRelationships.docs[0]
|
||||
expect(queriedDoc.title).toEqual(queriedDoc.relationToSelf.title)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by Payload.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
|
||||
@@ -8,99 +9,226 @@
|
||||
export interface Config {
|
||||
collections: {
|
||||
users: User
|
||||
point: Point
|
||||
posts: Post
|
||||
'custom-ids': CustomId
|
||||
relation: Relation
|
||||
dummy: Dummy
|
||||
'error-on-hooks': ErrorOnHook
|
||||
'payload-api-test-ones': PayloadApiTestOne
|
||||
'payload-api-test-twos': PayloadApiTestTwo
|
||||
'content-type': ContentType
|
||||
'cyclical-relationship': CyclicalRelationship
|
||||
'payload-preferences': PayloadPreference
|
||||
'payload-migrations': PayloadMigration
|
||||
}
|
||||
globals: {}
|
||||
locale: 'en' | 'es'
|
||||
user: User & {
|
||||
collection: 'users'
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "users".
|
||||
*/
|
||||
export interface User {
|
||||
id: string
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
email?: string
|
||||
resetPasswordToken?: string
|
||||
resetPasswordExpiration?: string
|
||||
loginAttempts?: number
|
||||
lockUntil?: string
|
||||
password?: string
|
||||
email: string
|
||||
resetPasswordToken?: string | null
|
||||
resetPasswordExpiration?: string | null
|
||||
salt?: string | null
|
||||
hash?: string | null
|
||||
loginAttempts?: number | null
|
||||
lockUntil?: string | null
|
||||
password?: string | null
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "point".
|
||||
*/
|
||||
export interface Point {
|
||||
id: string
|
||||
/**
|
||||
* @minItems 2
|
||||
* @maxItems 2
|
||||
*/
|
||||
point?: [number, number] | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "posts".
|
||||
*/
|
||||
export interface Post {
|
||||
id: string
|
||||
title?: string
|
||||
description?: string
|
||||
number?: number
|
||||
min?: number
|
||||
relationField?: string | Relation
|
||||
relationToCustomID?: number | CustomId
|
||||
relationHasManyField?: string[] | Relation[]
|
||||
title?: string | null
|
||||
description?: string | null
|
||||
number?: number | null
|
||||
min?: number | null
|
||||
relationField?: (string | null) | Relation
|
||||
relationToCustomID?: (number | null) | CustomId
|
||||
relationHasManyField?: (string | Relation)[] | null
|
||||
relationMultiRelationTo?:
|
||||
| {
|
||||
value: string | Relation
|
||||
| ({
|
||||
relationTo: 'relation'
|
||||
}
|
||||
| {
|
||||
value: string | Dummy
|
||||
value: string | Relation
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'dummy'
|
||||
}
|
||||
value: string | Dummy
|
||||
} | null)
|
||||
relationMultiRelationToHasMany?:
|
||||
| (
|
||||
| {
|
||||
value: string
|
||||
relationTo: 'relation'
|
||||
value: string | Relation
|
||||
}
|
||||
| {
|
||||
value: string
|
||||
relationTo: 'dummy'
|
||||
}
|
||||
)[]
|
||||
| (
|
||||
| {
|
||||
value: Relation
|
||||
relationTo: 'relation'
|
||||
}
|
||||
| {
|
||||
value: Dummy
|
||||
relationTo: 'dummy'
|
||||
value: string | Dummy
|
||||
}
|
||||
)[]
|
||||
| null
|
||||
A1?: {
|
||||
A2?: string
|
||||
A2?: string | null
|
||||
}
|
||||
B1?: {
|
||||
B2?: string
|
||||
B2?: string | null
|
||||
}
|
||||
C1?: {
|
||||
C2Text?: string | null
|
||||
C2?: {
|
||||
C3?: string
|
||||
C3?: string | null
|
||||
}
|
||||
}
|
||||
D1: {
|
||||
D2?: {
|
||||
D3?: {
|
||||
D4?: string
|
||||
D4?: string | null
|
||||
}
|
||||
}
|
||||
}
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "relation".
|
||||
*/
|
||||
export interface Relation {
|
||||
id: string
|
||||
name?: string
|
||||
name?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "custom-ids".
|
||||
*/
|
||||
export interface CustomId {
|
||||
id: number
|
||||
title?: string
|
||||
title?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "dummy".
|
||||
*/
|
||||
export interface Dummy {
|
||||
id: string
|
||||
name?: string
|
||||
name?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "error-on-hooks".
|
||||
*/
|
||||
export interface ErrorOnHook {
|
||||
id: string
|
||||
title?: string | null
|
||||
errorBeforeChange?: boolean | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-api-test-ones".
|
||||
*/
|
||||
export interface PayloadApiTestOne {
|
||||
id: string
|
||||
payloadAPI?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-api-test-twos".
|
||||
*/
|
||||
export interface PayloadApiTestTwo {
|
||||
id: string
|
||||
payloadAPI?: string | null
|
||||
relation?: (string | null) | PayloadApiTestOne
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "content-type".
|
||||
*/
|
||||
export interface ContentType {
|
||||
id: string
|
||||
contentType?: string | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "cyclical-relationship".
|
||||
*/
|
||||
export interface CyclicalRelationship {
|
||||
id: string
|
||||
title?: string | null
|
||||
relationToSelf?: (string | null) | CyclicalRelationship
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-preferences".
|
||||
*/
|
||||
export interface PayloadPreference {
|
||||
id: string
|
||||
user: {
|
||||
relationTo: 'users'
|
||||
value: string | User
|
||||
}
|
||||
key?: string | null
|
||||
value?:
|
||||
| {
|
||||
[k: string]: unknown
|
||||
}
|
||||
| unknown[]
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-migrations".
|
||||
*/
|
||||
export interface PayloadMigration {
|
||||
id: string
|
||||
name?: string | null
|
||||
batch?: number | null
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user