Skip to content

Commit a4fafea

Browse files
authored
Merge pull request #1072 from constructive-io/fix/presigned-url-mutation-step-type
fix(presigned-url): return PgSelectSingleStep from mutation entry points
2 parents 31a008c + c924768 commit a4fafea

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

  • graphile/graphile-presigned-url-plugin/src

graphile/graphile-presigned-url-plugin/src/plugin.ts

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,15 @@ export function createPresignedUrlPlugin(
174174

175175
const fieldName = typeName.charAt(0).toLowerCase() + typeName.slice(1);
176176
const hasOwnerId = !!codec.attributes.owner_id;
177-
const capturedCodec = codec;
177+
178+
// Find the PgResource for this codec so we can return a proper PgSelectSingleStep
179+
const bucketResource = Object.values((build.input as any).pgRegistry.pgResources).find(
180+
(r: any) => r.codec === codec && !r.isUnique && !r.isVirtual && !r.parameters,
181+
) as any;
182+
if (!bucketResource) {
183+
log.debug(`Skipping mutation entry point for ${codec.name}: no PgResource found`);
184+
continue;
185+
}
178186

179187
log.debug(`Adding mutation entry point "${fieldName}" for bucket type ${typeName} (entity-scoped=${hasOwnerId})`);
180188

@@ -190,41 +198,13 @@ export function createPresignedUrlPlugin(
190198
: {}),
191199
},
192200
plan(_$mutation: any, fieldArgs: any) {
193-
const $key = fieldArgs.getRaw('key');
194-
const $ownerId = hasOwnerId ? fieldArgs.getRaw('ownerId') : lambda(null, (): null => null);
195-
const $withPgClient = (grafastContext() as any).get('withPgClient');
196-
const $pgSettings = (grafastContext() as any).get('pgSettings');
197-
198-
const $combined = object({
199-
key: $key,
200-
ownerId: $ownerId,
201-
withPgClient: $withPgClient,
202-
pgSettings: $pgSettings,
203-
});
204-
205-
const $row = lambda($combined, async (vals: any) => {
206-
return vals.withPgClient(vals.pgSettings, async (pgClient: any) => {
207-
const databaseId = await resolveDatabaseId(pgClient);
208-
if (!databaseId) throw new Error('DATABASE_NOT_FOUND');
209-
210-
const allConfigs = await loadAllStorageModules(pgClient, databaseId);
211-
const storageConfig = resolveStorageConfigFromCodec(capturedCodec, allConfigs);
212-
if (!storageConfig) throw new Error('STORAGE_MODULE_NOT_FOUND');
213-
214-
const bucket = await getBucketConfig(
215-
pgClient, storageConfig, databaseId, vals.key, vals.ownerId ?? undefined,
216-
);
217-
if (!bucket) throw new Error('BUCKET_NOT_FOUND');
218-
219-
return bucket;
220-
});
221-
});
222-
223-
const columnEntries: Record<string, any> = {};
224-
for (const col of Object.keys(capturedCodec.attributes)) {
225-
columnEntries[col] = access($row, col);
201+
const spec: Record<string, any> = {
202+
key: fieldArgs.getRaw('key'),
203+
};
204+
if (hasOwnerId) {
205+
spec.owner_id = fieldArgs.getRaw('ownerId');
226206
}
227-
return object(columnEntries);
207+
return bucketResource.find(spec).single();
228208
},
229209
},
230210
);

0 commit comments

Comments
 (0)