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

Fix subscription result & improve types #13047

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/api-graphql/src/internals/operations/get.ts
Expand Up @@ -13,9 +13,10 @@ import {
import {
AuthModeParams,
ClientWithModels,
ConfigurableHeadersParams,
FieldSelectionParams,
GraphQLOptionsV6,
GraphQLResult,
ListArgs,
QueryArgs,
V6Client,
V6ClientSSRRequest,
Expand Down Expand Up @@ -60,7 +61,7 @@ async function _get(
modelIntrospection: ModelIntrospectionSchema,
model: SchemaModel,
arg: QueryArgs,
options: AuthModeParams & ListArgs,
options: AuthModeParams & ConfigurableHeadersParams & FieldSelectionParams,
operation: ModelOperation,
context?: AmplifyServer.ContextSpec,
) {
Expand Down
27 changes: 16 additions & 11 deletions packages/api-graphql/src/internals/operations/subscription.ts
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { map } from 'rxjs';
import { V6Client, GraphqlSubscriptionResult } from '../../types';
import { V6Client, GraphqlSubscriptionResult, ListArgs, AuthModeParams } from '../../types';
import {
initializeModel,
generateGraphQLDocument,
Expand All @@ -24,7 +24,7 @@ export function subscriptionFactory(
) {
const { name } = model as any;

const subscription = (args?: any) => {
const subscription = (args?: ListArgs & AuthModeParams) => {
const query = generateGraphQLDocument(
modelIntrospection,
name,
Expand Down Expand Up @@ -56,15 +56,20 @@ export function subscriptionFactory(
map(value => {
const [key] = Object.keys(value.data);
const data = (value.data as any)[key];
const [initialized] = initializeModel(
client as V6Client<Record<string, any>>,
name,
[data],
modelIntrospection,
auth.authMode,
auth.authToken,
);
return initialized;

if (args?.selectionSet) {
return data;
} else {
const [initialized] = initializeModel(
client as V6Client<Record<string, any>>,
name,
[data],
modelIntrospection,
auth.authMode,
auth.authToken,
);
return initialized;
}
}),
);
};
Expand Down
10 changes: 8 additions & 2 deletions packages/api-graphql/src/types/index.ts
Expand Up @@ -457,12 +457,18 @@ export type ServerClientGenerationParams = {

export type QueryArgs = Record<string, unknown>;

export type ListArgs = {
export type FieldSelectionParams = {
selectionSet?: string[];
filter?: {};
};

export type ConfigurableHeadersParams = {
headers?: CustomHeaders;
};

export type ListArgs = {
filter?: {};
} & ConfigurableHeadersParams & FieldSelectionParams;

export type AuthModeParams = {
authMode?: GraphQLAuthMode;
authToken?: string;
Expand Down