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(deps): update dependency undici to v4.4.1 #2628

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ declare interface ObjectConstructor {
keys<T>(obj: T): Array<keyof T>;
}
declare module 'ajv-formats';
declare module 'undici' {
export const fetch: typeof import('cross-fetch').fetch;
export const Request: typeof import('cross-fetch').Request;
export const Response: typeof import('cross-fetch').Response;
}
2 changes: 1 addition & 1 deletion packages/handlers/odata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"graphql-scalars": "1.10.0",
"pascal-case": "3.1.2",
"url-join": "4.0.1",
"undici": "4.3.1"
"undici": "4.4.1"
},
"publishConfig": {
"access": "public",
Expand Down
7 changes: 3 additions & 4 deletions packages/handlers/odata/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ import {
import { parseResolveInfo, ResolveTree, simplifyParsedResolveInfoFragmentWithType } from 'graphql-parse-resolve-info';
import DataLoader from 'dataloader';
import { parseResponse } from 'http-string-parser';
import { nativeFetch } from './native-fetch';
import { pascalCase } from 'pascal-case';
import { EventEmitter } from 'events';
import { parse as parseXML } from 'fast-xml-parser';
import { pruneSchema } from '@graphql-tools/utils';
import { Request, Response } from 'cross-fetch';
import { PredefinedProxyOptions } from '@graphql-mesh/store';
import { env } from 'process';
import { fetch as nativeFetch, Request, Response } from 'undici';

const SCALARS = new Map<string, string>([
['Edm.Binary', 'String'],
Expand Down Expand Up @@ -174,7 +173,7 @@ export default class ODataHandler implements MeshHandler {
})
: this.config.customFetch;
} else {
fetch = getCachedFetch(this.cache);
fetch = nativeFetch;
}

const { baseUrl: nonInterpolatedBaseUrl, operationHeaders } = this.config;
Expand Down Expand Up @@ -924,7 +923,7 @@ export default class ODataHandler implements MeshHandler {
// If entitySetPath is not available, take first parameter as entity
// The first segment of the entity set path must match the binding parameter name
// (see: http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530388)
entitySetPath = entitySetPath && entitySetPath.split("/")[0] || parameterName;
entitySetPath = (entitySetPath && entitySetPath.split('/')[0]) || parameterName;
if (entitySetPath === parameterName) {
boundEntityTypeName = getTypeNameFromRef({
typeRef: parameterTypeRef,
Expand Down
33 changes: 0 additions & 33 deletions packages/handlers/odata/src/native-fetch.ts

This file was deleted.

30 changes: 20 additions & 10 deletions packages/handlers/odata/test/handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('odata', () => {
});
const source = await handler.getMeshSource();
const personType = source.schema.getType('IPerson') as GraphQLInterfaceType;
const getFriendsTripsFunction = personType.getFields()['GetFriendsTrips'];
const getFriendsTripsFunction = personType.getFields().GetFriendsTrips;
expect(getFriendsTripsFunction.args).toHaveLength(2);
const personArg = getFriendsTripsFunction.args.find(arg => arg.name === 'person');
expect(personArg).not.toBeFalsy();
Expand Down Expand Up @@ -301,11 +301,16 @@ describe('odata', () => {
],
};
let sentRequest: Request;
let sentBody: any;
addMock(correctUrl, async request => {
sentRequest = request;
const bodyObj = JSON.parse(request.body as any);
bodyObj['@odata.type'] = 'Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person';
return new Response(JSON.stringify(bodyObj));
sentBody = await request.json();
return new Response(
JSON.stringify({
...sentBody,
'@odata.type': 'Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person',
})
);
});
const handler = new ODataHandler({
name: 'TripPin',
Expand Down Expand Up @@ -337,7 +342,7 @@ describe('odata', () => {
expect(graphqlResult.errors).toBeFalsy();
expect(sentRequest!.method).toBe(correctMethod);
expect(sentRequest!.url).toBe(correctUrl);
expect(JSON.parse(sentRequest!.body as any)).toStrictEqual(correctBody);
expect(sentBody).toStrictEqual(correctBody);
});
it('should generate correct HTTP request for deleting an entity', async () => {
addMock('https://services.odata.org/TripPinRESTierService/$metadata', async () => new Response(TripPinMetadata));
Expand Down Expand Up @@ -383,11 +388,16 @@ describe('odata', () => {
LastName: 'King',
};
let sentRequest: Request;
let sentBody: any;
addMock(correctUrl, async request => {
sentRequest = request;
const returnBody = JSON.parse(request.body as any);
returnBody['@odata.type'] = 'Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person';
return new Response(JSON.stringify(returnBody));
sentBody = await request.json();
return new Response(
JSON.stringify({
...sentBody,
'@odata.type': 'Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person',
})
);
});
const handler = new ODataHandler({
name: 'TripPin',
Expand Down Expand Up @@ -420,7 +430,7 @@ describe('odata', () => {
expect(graphqlResult.errors).toBeFalsy();
expect(sentRequest!.method).toBe(correctMethod);
expect(sentRequest!.url).toBe(correctUrl);
expect(await sentRequest!.text()).toBe(JSON.stringify(correctBody));
expect(sentBody).toStrictEqual(correctBody);
});
it('should generate correct HTTP request for invoking unbound functions', async () => {
addMock('https://services.odata.org/TripPinRESTierService/$metadata', async () => new Response(TripPinMetadata));
Expand Down Expand Up @@ -568,7 +578,7 @@ describe('odata', () => {

expect(graphqlResult.errors).toBeFalsy();
expect(sentRequest!.method).toBe(correctMethod);
expect(sentRequest!.url).toBe(correctUrl.replace(/'/g, '%27', ));// apostrophe gets percent-encoded
expect(sentRequest!.url).toBe(correctUrl);
});
it('should generate correct HTTP request for invoking unbound actions', async () => {
addMock('https://services.odata.org/TripPinRESTierService/$metadata', async () => new Response(TripPinMetadata));
Expand Down
Loading