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

Relax type to be able to use extract-files properly #2292

Merged
merged 5 commits into from
Sep 18, 2024
Merged
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 .changeset/nine-knives-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'apollo-angular': patch
---

Relax type to be able to use `extract-files` properly
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/.changeset/
/.devcontainer/
/packages/apollo-angular/CHANGELOG.md
/packages/apollo-angular/dist/
/packages/demo/.angular/
/packages/demo/dist/
/scripts/

# Needed because TextEncoder workaround must happen before importing @angular-devkit/schematics
/packages/apollo-angular/schematics/tests/ng-add.spec.ts
Expand Down
6 changes: 4 additions & 2 deletions packages/apollo-angular/http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export type Request = {
options: HttpRequestOptions;
};

export type ExtractFiles = (body: Body | Body[]) => {
clone: Body;
export type ExtractedFiles = {
clone: unknown;
files: Map<any, any>;
};

export type ExtractFiles = (body: Body | Body[]) => ExtractedFiles;

export type BatchOptions = {
batchMax?: number;
batchInterval?: number;
Expand Down
7 changes: 2 additions & 5 deletions packages/apollo-angular/http/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Body, ExtractFiles, Request } from './types';
import { Body, ExtractedFiles, ExtractFiles, Request } from './types';

export const fetch = (
req: Request,
Expand All @@ -12,10 +12,7 @@ export const fetch = (
['variables', 'extensions'].indexOf(param.toLowerCase()) !== -1;
const isBatching = (req.body as Body[]).length;
let shouldUseMultipart = req.options && req.options.useMultipart;
let multipartInfo: {
clone: Body;
files: Map<any, any>;
};
let multipartInfo: ExtractedFiles;

if (shouldUseMultipart) {
if (isBatching) {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/src/app/pages/author/author-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Query {
`,
})
export class AuthorPageComponent implements OnInit {
posts: Observable<Post[]>;
posts!: Observable<Post[]>;
constructor(
private readonly apollo: Apollo,
private readonly route: ActivatedRoute,
Expand All @@ -48,7 +48,7 @@ export class AuthorPageComponent implements OnInit {
}
`,
variables: {
authorId: parseInt(this.route.snapshot.paramMap.get('id'), 10),
authorId: parseInt(this.route.snapshot.paramMap.get('id') as string, 10),
},
})
.valueChanges.pipe(map(result => result.data.postsOf));
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/app/pages/posts/posts-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface Query {
`,
})
export class PostsPageComponent implements OnInit {
posts: Observable<Post[]>;
posts!: Observable<Post[]>;
constructor(private readonly apollo: Apollo) {}

ngOnInit() {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/app/pages/posts/upvoter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Component, Input } from '@angular/core';
template: ` <button (click)="upvote()">Upvote</button> `,
})
export class UpvoterComponent {
@Input() postId: number;
@Input() postId!: number;

constructor(private readonly apollo: Apollo) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": false,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
Expand Down
3 changes: 2 additions & 1 deletion website/src/pages/docs/data/network.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ You also have to define `extractFiles` function:

```ts
import extractFiles from 'extract-files/extractFiles.mjs';
import isExtractableFile from 'extract-files/isExtractableFile.mjs';

// the import depends on the version of `extract-files`

Expand All @@ -170,7 +171,7 @@ import extractFiles from 'extract-files/extractFiles.mjs';
return {
link: httpLink.create({
uri: '/graphql',
extractFiles, // <-
extractFiles: body => extractFiles(body, isExtractableFile), // <-
}),
cache: new InMemoryCache(),
};
Expand Down
Loading