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

How to get all comments (any relation) by a user with GraphQL? #209

Closed
jnovak-SM2Dev opened this issue May 18, 2023 · 8 comments
Closed
Labels
backlog feature request Community feature request graphql GraphQL API issue rest REST API issue solved Issue has been solved v4 Strapi v4

Comments

@jnovak-SM2Dev
Copy link

I'm trying to get all the comments by a user to show on their profile page, but the GraphQL findAllFlat and findAllInHierarchy calls require a relation. Is there a way to do this or does anyone know the best way to override the calls to make the relation optional so I can use the author filter only?

@cyp3rius
Copy link
Collaborator

Hello @SM2DevLLC, that seems as a feature request.

I'll schedule development for this.

@cyp3rius cyp3rius added feature request Community feature request v4 Strapi v4 backlog graphql GraphQL API issue rest REST API issue labels May 19, 2023
@jnovak-SM2Dev
Copy link
Author

@cyp3rius Sounds good. Thanks! I'm surprised no one else has wanted to show a users comments on a profile page or something like that before.

@jnovak-SM2Dev
Copy link
Author

@cyp3rius I found a workaround for now. I'll leave this here in case it helps anyone else.

This goes in the index.ts (might be index.js if you aren't using typescript). This adds a query called findAllFlatAuthor where you don't need to pass in the related string, but instead pass in an authorId. I added more code to mine that also lets you get the related object as a response (which seems to be missing from this plugin as well).

export default {
  register({ strapi }) {
    const extensionService = strapi.plugin("graphql").service("extension");
    extensionService.use(({ strapi }) => ({
      typeDefs: `
    type Query {
      findAllFlatAuthor(authorId: String!, pagination: PaginationArg = {}, sort: [String] = []): ResponseFindAll
    }
  `,
      resolvers: {
        Query: {
          findAllFlatAuthor: {
            resolve: async (parent, args, context) => {
              const { toEntityCollectionResponse } = strapi.service(
                "plugin::graphql.format"
              ).returnTypes;

              const data = await strapi.services[
                "plugin::comments.common"
              ].findAllFlat({
                query: {
                  authorId: args.authorId,
                },
                pagination: args.pagination
                  ? {
                    ...args.pagination,
                    withCount: true,
                  }
                  : undefined,
                sort: args.sort,
              });

              return data;
            },
          },
        },
      },
    }));
  }
}

@cyp3rius
Copy link
Collaborator

Thats one of the way here :) If you are using extensions approach.

As you already got it for your own purposes, may I ask you to contribute and implement similar approach by adding route, controller and service methods? :) Would be really nice.

@jnovak-SM2Dev
Copy link
Author

@cyp3rius I would, but I have no idea how. I'm only using GraphQL in my project and this is my first Strapi project. I'm not using routes/controllers/services. I could try and take a look at some point, but i'm not sure where i'd even start with those.

cyp3rius added a commit that referenced this issue Jun 4, 2023
cyp3rius added a commit that referenced this issue Jun 4, 2023
cyp3rius added a commit that referenced this issue Jun 5, 2023
cyp3rius added a commit that referenced this issue Jun 5, 2023
…ch-comments-by-author

feat(api): issue #209 - find all by author
@cyp3rius
Copy link
Collaborator

cyp3rius commented Jun 5, 2023

Endpoint + GQL Query published as part of v2.2.11. Hope it fulfils your requirements :)

@cyp3rius cyp3rius closed this as completed Jun 5, 2023
@cyp3rius cyp3rius added solved Issue has been solved and removed in progress labels Jun 5, 2023
@jnovak-SM2Dev
Copy link
Author

@cyp3rius Sorry, didn't see your last message. Yes it does help a lot. Only one issue, how can I get the related item? I'd need to be able to link to the related item and show related details. For example, if the comment is on a blog post, i'd need to show the title of the blog post and link to it.

Also, the author field does not populate properly.

@jnovak-SM2Dev
Copy link
Author

@cyp3rius I add this to my version to allow being able to pull related items.

extensionService.use(({ strapi }) => ({
  typeDefs: `
    union Related = ArticleEntity | PodcastEntity
    type CommentSingle {
      related: Related
    }
  `,
  resolvers: {
    Related: {
      __resolveType(x) {
        switch (x.uid) {
          case "api::article.article": {
            return "ArticleEntity";
          }
          case "api::podcast.podcast": {
            return "PodcastEntity";
          }
          default: {
            return null;
          }
        }
      },
    },
  },
}));

mkmak2 pushed a commit that referenced this issue Sep 18, 2023
github-actions bot pushed a commit to zrp/uqbar-strapi-plugin-comments that referenced this issue Oct 4, 2023
# [1.1.0](v1.0.2...v1.1.0) (2023-10-04)

### Bug Fixes

* add types to Avatar component ([f12ea9c](f12ea9c))
* author blocked props ([d9d0777](d9d0777))
* author population ([VirtusLab-Open-Source#177](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/177)) ([5ba0d85](5ba0d85))
* change error 403 test ([99ec162](99ec162))
* custom field on existing entity ([VirtusLab-Open-Source#178](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/178)) ([5e6cc63](5e6cc63))
* fixed UserAvatar typing ([dd179c7](dd179c7))
* fixes after merge ([3b9eee2](3b9eee2))
* issue [VirtusLab-Open-Source#199](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/199) - undeclared codemirror dependency causes build crash ([ccc1f98](ccc1f98))
* issue [VirtusLab-Open-Source#201](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/201) fix the filtering by thread ([bdc292a](bdc292a))
* issue [VirtusLab-Open-Source#220](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/220), issue [VirtusLab-Open-Source#221](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/221) ([VirtusLab-Open-Source#222](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/222)) ([03d504a](03d504a))
* load only existing translations ([e0cea8d](e0cea8d))
* package.json outdated ([1ef26e5](1ef26e5))
* peer dependency ([50bd59c](50bd59c))
* stick to older match-sorter dependency following strapi ([70dd408](70dd408))
* strapi 4.13 packages alignment ([VirtusLab-Open-Source#229](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/229)) ([3432cd2](3432cd2))
* strapi v4.7.1 compatibility fix because of dependencies ([563f86c](563f86c))
* unused import removed ([ac7d47f](ac7d47f))

### Features

* **api:** issue [VirtusLab-Open-Source#209](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/209) - find all by author ([e47684a](e47684a))
* author entity props blocking ([VirtusLab-Open-Source#186](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/186)) ([6134f1e](6134f1e))
* basic filters options added to Discover and Reports ([074d23a](074d23a))
* comments custom field [CU-2tn2923] ([VirtusLab-Open-Source#157](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/157)) ([aaac8a0](aaac8a0)), closes [VirtusLab-Open-Source#158](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/158)
* create reports page [CU-20rfmkv] ([VirtusLab-Open-Source#153](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/153)) ([15b9b57](15b9b57))
* custom fields on server-side [CU-xhcmx-63] ([VirtusLab-Open-Source#161](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/161)) ([a284d59](a284d59))
* typescripted client service and controllers ([eddd4b3](eddd4b3))
gabrielsclimaco pushed a commit to zrp/uqbar-strapi-plugin-comments that referenced this issue Dec 20, 2023
# [1.1.0](v1.0.2...v1.1.0) (2023-10-04)

### Bug Fixes

* add types to Avatar component ([f12ea9c](f12ea9c))
* author blocked props ([d9d0777](d9d0777))
* author population ([VirtusLab-Open-Source#177](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/177)) ([5ba0d85](5ba0d85))
* change error 403 test ([99ec162](99ec162))
* custom field on existing entity ([VirtusLab-Open-Source#178](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/178)) ([5e6cc63](5e6cc63))
* fixed UserAvatar typing ([dd179c7](dd179c7))
* fixes after merge ([3b9eee2](3b9eee2))
* issue [VirtusLab-Open-Source#199](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/199) - undeclared codemirror dependency causes build crash ([ccc1f98](ccc1f98))
* issue [VirtusLab-Open-Source#201](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/201) fix the filtering by thread ([bdc292a](bdc292a))
* issue [VirtusLab-Open-Source#220](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/220), issue [VirtusLab-Open-Source#221](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/221) ([VirtusLab-Open-Source#222](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/222)) ([03d504a](03d504a))
* load only existing translations ([e0cea8d](e0cea8d))
* package.json outdated ([1ef26e5](1ef26e5))
* peer dependency ([50bd59c](50bd59c))
* stick to older match-sorter dependency following strapi ([70dd408](70dd408))
* strapi 4.13 packages alignment ([VirtusLab-Open-Source#229](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/229)) ([3432cd2](3432cd2))
* strapi v4.7.1 compatibility fix because of dependencies ([563f86c](563f86c))
* unused import removed ([ac7d47f](ac7d47f))

### Features

* **api:** issue [VirtusLab-Open-Source#209](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/209) - find all by author ([e47684a](e47684a))
* author entity props blocking ([VirtusLab-Open-Source#186](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/186)) ([6134f1e](6134f1e))
* basic filters options added to Discover and Reports ([074d23a](074d23a))
* comments custom field [CU-2tn2923] ([VirtusLab-Open-Source#157](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/157)) ([aaac8a0](aaac8a0)), closes [VirtusLab-Open-Source#158](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/158)
* create reports page [CU-20rfmkv] ([VirtusLab-Open-Source#153](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/153)) ([15b9b57](15b9b57))
* custom fields on server-side [CU-xhcmx-63] ([VirtusLab-Open-Source#161](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/161)) ([a284d59](a284d59))
* typescripted client service and controllers ([eddd4b3](eddd4b3))
gabrielsclimaco pushed a commit to zrp/uqbar-strapi-plugin-comments that referenced this issue Dec 20, 2023
* add types to Avatar component ([f12ea9c](f12ea9c))
* author blocked props ([d9d0777](d9d0777))
* author population ([VirtusLab-Open-Source#177](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/177)) ([5ba0d85](5ba0d85))
* change error 403 test ([99ec162](99ec162))
* custom field on existing entity ([VirtusLab-Open-Source#178](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/178)) ([5e6cc63](5e6cc63))
* fixed UserAvatar typing ([dd179c7](dd179c7))
* fixes after merge ([3b9eee2](3b9eee2))
* issue [VirtusLab-Open-Source#199](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/199) - undeclared codemirror dependency causes build crash ([ccc1f98](ccc1f98))
* issue [VirtusLab-Open-Source#201](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/201) fix the filtering by thread ([bdc292a](bdc292a))
* issue [VirtusLab-Open-Source#220](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/220), issue [VirtusLab-Open-Source#221](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/221) ([VirtusLab-Open-Source#222](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/222)) ([03d504a](03d504a))
* load only existing translations ([e0cea8d](e0cea8d))
* package.json outdated ([1ef26e5](1ef26e5))
* peer dependency ([50bd59c](50bd59c))
* stick to older match-sorter dependency following strapi ([70dd408](70dd408))
* strapi 4.13 packages alignment ([VirtusLab-Open-Source#229](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/229)) ([3432cd2](3432cd2))
* strapi v4.7.1 compatibility fix because of dependencies ([563f86c](563f86c))
* unused import removed ([ac7d47f](ac7d47f))

* **api:** issue [VirtusLab-Open-Source#209](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/209) - find all by author ([e47684a](e47684a))
* author entity props blocking ([VirtusLab-Open-Source#186](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/186)) ([6134f1e](6134f1e))
* basic filters options added to Discover and Reports ([074d23a](074d23a))
* comments custom field [CU-2tn2923] ([VirtusLab-Open-Source#157](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/157)) ([aaac8a0](aaac8a0)), closes [VirtusLab-Open-Source#158](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/158)
* create reports page [CU-20rfmkv] ([VirtusLab-Open-Source#153](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/153)) ([15b9b57](15b9b57))
* custom fields on server-side [CU-xhcmx-63] ([VirtusLab-Open-Source#161](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/161)) ([a284d59](a284d59))
* typescripted client service and controllers ([eddd4b3](eddd4b3))
gabrielsclimaco pushed a commit to zrp/uqbar-strapi-plugin-comments that referenced this issue Dec 20, 2023
* add types to Avatar component ([f12ea9c](f12ea9c))
* author blocked props ([d9d0777](d9d0777))
* author population ([VirtusLab-Open-Source#177](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/177)) ([5ba0d85](5ba0d85))
* change error 403 test ([99ec162](99ec162))
* custom field on existing entity ([VirtusLab-Open-Source#178](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/178)) ([5e6cc63](5e6cc63))
* fixed UserAvatar typing ([dd179c7](dd179c7))
* fixes after merge ([3b9eee2](3b9eee2))
* issue [VirtusLab-Open-Source#199](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/199) - undeclared codemirror dependency causes build crash ([ccc1f98](ccc1f98))
* issue [VirtusLab-Open-Source#201](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/201) fix the filtering by thread ([bdc292a](bdc292a))
* issue [VirtusLab-Open-Source#220](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/220), issue [VirtusLab-Open-Source#221](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/221) ([VirtusLab-Open-Source#222](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/222)) ([03d504a](03d504a))
* load only existing translations ([e0cea8d](e0cea8d))
* package.json outdated ([1ef26e5](1ef26e5))
* peer dependency ([50bd59c](50bd59c))
* stick to older match-sorter dependency following strapi ([70dd408](70dd408))
* strapi 4.13 packages alignment ([VirtusLab-Open-Source#229](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/229)) ([3432cd2](3432cd2))
* strapi v4.7.1 compatibility fix because of dependencies ([563f86c](563f86c))
* unused import removed ([ac7d47f](ac7d47f))

* **api:** issue [VirtusLab-Open-Source#209](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/209) - find all by author ([e47684a](e47684a))
* author entity props blocking ([VirtusLab-Open-Source#186](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/186)) ([6134f1e](6134f1e))
* basic filters options added to Discover and Reports ([074d23a](074d23a))
* comments custom field [CU-2tn2923] ([VirtusLab-Open-Source#157](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/157)) ([aaac8a0](aaac8a0)), closes [VirtusLab-Open-Source#158](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/158)
* create reports page [CU-20rfmkv] ([VirtusLab-Open-Source#153](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/153)) ([15b9b57](15b9b57))
* custom fields on server-side [CU-xhcmx-63] ([VirtusLab-Open-Source#161](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/161)) ([a284d59](a284d59))
* typescripted client service and controllers ([eddd4b3](eddd4b3))
github-actions bot pushed a commit to zrp/uqbar-strapi-plugin-comments that referenced this issue Dec 20, 2023
# [1.1.0](v1.0.2...v1.1.0) (2023-12-20)

### Bug Fixes

* add types to Avatar component ([f12ea9c](f12ea9c))
* author blocked props ([d9d0777](d9d0777))
* author population ([VirtusLab-Open-Source#177](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/177)) ([5ba0d85](5ba0d85))
* change error 403 test ([99ec162](99ec162))
* custom field on existing entity ([VirtusLab-Open-Source#178](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/178)) ([5e6cc63](5e6cc63))
* fixed UserAvatar typing ([dd179c7](dd179c7))
* fixes after merge ([3b9eee2](3b9eee2))
* issue [VirtusLab-Open-Source#199](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/199) - undeclared codemirror dependency causes build crash ([ccc1f98](ccc1f98))
* issue [VirtusLab-Open-Source#201](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/201) fix the filtering by thread ([bdc292a](bdc292a))
* issue [VirtusLab-Open-Source#220](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/220), issue [VirtusLab-Open-Source#221](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/221) ([VirtusLab-Open-Source#222](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/222)) ([03d504a](03d504a))
* load only existing translations ([e0cea8d](e0cea8d))
* package.json outdated ([1ef26e5](1ef26e5))
* peer dependency ([50bd59c](50bd59c))
* stick to older match-sorter dependency following strapi ([70dd408](70dd408))
* strapi 4.13 packages alignment ([VirtusLab-Open-Source#229](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/229)) ([3432cd2](3432cd2))
* strapi v4.7.1 compatibility fix because of dependencies ([563f86c](563f86c))
* unused import removed ([ac7d47f](ac7d47f))

### Features

* **api:** issue [VirtusLab-Open-Source#209](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/209) - find all by author ([e47684a](e47684a))
* author entity props blocking ([VirtusLab-Open-Source#186](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/186)) ([6134f1e](6134f1e))
* basic filters options added to Discover and Reports ([074d23a](074d23a))
* comments custom field [CU-2tn2923] ([VirtusLab-Open-Source#157](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/157)) ([aaac8a0](aaac8a0)), closes [VirtusLab-Open-Source#158](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/158)
* create reports page [CU-20rfmkv] ([VirtusLab-Open-Source#153](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/153)) ([15b9b57](15b9b57))
* custom fields on server-side [CU-xhcmx-63] ([VirtusLab-Open-Source#161](https://github.com/zrp/uqbar-strapi-plugin-comments/issues/161)) ([a284d59](a284d59))
* typescripted client service and controllers ([eddd4b3](eddd4b3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog feature request Community feature request graphql GraphQL API issue rest REST API issue solved Issue has been solved v4 Strapi v4
Projects
None yet
Development

No branches or pull requests

2 participants