Skip to content

Commit

Permalink
Fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Feb 22, 2025
1 parent ee8356e commit ed73958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions packages/transports/soap/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
getInterpolatedHeadersFactory,
stringInterpolator,
} from '@graphql-mesh/string-interpolation';
import type { MeshFetch } from '@graphql-mesh/types';
import type { Logger, MeshFetch } from '@graphql-mesh/types';
import { DefaultLogger } from '@graphql-mesh/utils';
import { normalizedExecutor } from '@graphql-tools/executor';
import {
createGraphQLError,
Expand Down Expand Up @@ -105,6 +106,7 @@ interface CreateRootValueMethodOpts {
jsonToXMLConverter: JSONToXMLConverter;
xmlToJSONConverter: XMLParser;
operationHeadersFactory: ResolverDataBasedFactory<Record<string, string>>;
logger: Logger;
}

function prefixWithAlias({
Expand Down Expand Up @@ -140,7 +142,14 @@ function createRootValueMethod({
jsonToXMLConverter,
xmlToJSONConverter,
operationHeadersFactory,
logger,
}: CreateRootValueMethodOpts): RootValueMethod {
if (soapAnnotations.soapNamespace) {
logger.warn(`The expected 'soapNamespace' attribute is missing in SOAP directive definition.
Update the SOAP source handler, and re-generate the schema.
Falling back to 'http://www.w3.org/2003/05/soap-envelope' as SOAP Namespace.`);
soapAnnotations.soapNamespace = 'http://www.w3.org/2003/05/soap-envelope';
}
return async function rootValueMethod(args: any, context: any, info: GraphQLResolveInfo) {
const envelopeAttributes: Record<string, string> = {
'xmlns:soap': soapAnnotations.soapNamespace,
Expand Down Expand Up @@ -258,6 +267,7 @@ function createRootValue(
schema: GraphQLSchema,
fetchFn: MeshFetch,
operationHeaders: Record<string, string>,
logger: Logger,
) {
const rootValue: Record<string, RootValueMethod> = {};
const rootTypes = getRootTypes(schema);
Expand Down Expand Up @@ -289,6 +299,7 @@ function createRootValue(
jsonToXMLConverter,
xmlToJSONConverter,
operationHeadersFactory,
logger,
});
}
}
Expand All @@ -300,11 +311,12 @@ export function createExecutorFromSchemaAST(
schema: GraphQLSchema,
fetchFn: MeshFetch = defaultFetchFn,
operationHeaders: Record<string, string> = {},
logger: Logger = new DefaultLogger(),
): Executor {
let rootValue: Record<string, RootValueMethod>;
return function soapExecutor({ document, variables, context }) {
if (!rootValue) {
rootValue = createRootValue(schema, fetchFn, operationHeaders);
rootValue = createRootValue(schema, fetchFn, operationHeaders, logger);
}
return normalizedExecutor({
schema,
Expand Down
4 changes: 2 additions & 2 deletions packages/transports/soap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { createExecutorFromSchemaAST } from './executor.js';
export { createExecutorFromSchemaAST } from './executor.js';

export default {
getSubgraphExecutor({ transportEntry, subgraph, fetch }) {
getSubgraphExecutor({ transportEntry, subgraph, fetch, logger }) {
let headers: Record<string, string> | undefined;
if (typeof transportEntry.headers === 'string') {
headers = JSON.parse(transportEntry.headers);
}
if (Array.isArray(transportEntry.headers)) {
headers = Object.fromEntries(transportEntry.headers);
}
return createExecutorFromSchemaAST(subgraph, fetch, headers);
return createExecutorFromSchemaAST(subgraph, fetch, headers, logger);
},
} satisfies Transport;

0 comments on commit ed73958

Please sign in to comment.