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

Apos3: document the need to include 'type' in the publicApiProjection and flag a missing type as a probable missing projection property. #3626

Open
ThomasVuillaume opened this issue Jan 18, 2022 · 9 comments
Labels

Comments

@ThomasVuillaume
Copy link
Contributor

To Reproduce

Step by step instructions to reproduce the behavior:

  1. Create a piece-type with the given file, in the module/presentation folder :
module.exports = {
  extend: '@apostrophecms/piece-type',
  options: {
    label: 'Présentation',
    pluralLabel: 'Présentations',
    publicApiProjection: {
      title: 1,
      body: 1,
    }
  },
  fields: {
    add: {
      title: {
        label: 'Titre de la sous-section de présentation',
        type: 'string',
        required: true
      },
      body: {
        label: 'Corps de la présentation',
        type: 'area',
        options: {
          widgets: {
            '@apostrophecms/rich-text': {
              toolbar: ['styles', 'bold', 'italic'],
              styles: [
                {
                  tag: 'p',
                  label: 'Paragraph (P)'
                },
                {
                  tag: 'h3',
                  label: 'Heading 3 (H3)'
                }
              ]
            }
          }
        },
        required: true
      },
    },
    group: {
      homePresentationFields: {
        label: 'Section Présentation',
        fields: ['title', 'body']
      }
    }
  }
};

  1. Run the apostrophe server with npm run dev
  2. Make an API call to http://localhost:3001/api/v1/homePresentation
  3. See the warning in the console

image

Expected behavior

There should not be warning in this case.

Details

Version of Node.js:
Node v16.13.2. but reproduced on 12 too.

Server Operating System:
Reproduced on Windows, Linux, inside a Docker.

Workaround
Adding type :1 to publicApiProjection makes the warning disapear.

@boutell
Copy link
Member

boutell commented Jan 18, 2022

If type is not part of the response then Apostrophe cannot figure out what to do with the documents because it cannot figure out what type they have and therefore what module manages them.

That doesn't mean this isn't a legitimate ticket, but it might be recast as "document the need to include 'type' in the publicApiProjection and flag a missing type as a probable missing projection property."

@boutell boutell changed the title Apos3 - Error A permission.can() call was made with a type that has no manager when calling piece-type API Apos3: document the need to include 'type' in the publicApiProjection and flag a missing type as a probable missing projection property. Jan 18, 2022
@boutell
Copy link
Member

boutell commented Jan 18, 2022

I changed the title accordingly. Perhaps you'd be interested in submitting PRs to a3-docs and apostrophe to take care of those things?

@abea
Copy link
Contributor

abea commented Jan 18, 2022

Since Apostrophe requires it is there a reason we wouldn't ensure that it's there regardless of the option? I'm not sure why we'd require developers using the public api projection option to know about a core code requirement.

@boutell
Copy link
Member

boutell commented Jan 18, 2022

That's a fair question. We could always add type.

@ThomasVuillaume
Copy link
Contributor Author

I agree with Alex, if it is always needed by the Apostrophe core we should not be specially aware about it.

@myovchev
Copy link
Contributor

myovchev commented Jan 27, 2022

@boutell I think I'm witnessing the same behavior (console warning) without any custom projections but using the piece built in relation filter (think of articles filtered by a tag). The strange part is I'm seeing it only when not logged in. I can not confirm it 100% yet because I really lack time to set up a clean PoC. The debug shows me can receives only `{ _id: xxx } object. Could it be an internal routine (the built in relation type query)?

@boutell
Copy link
Member

boutell commented Jan 27, 2022 via email

@myovchev
Copy link
Contributor

@boutell https://github.com/myovchev/apos-issue-3626
Ccreate an article, assign a tag, create and navigate to an article page type, click the tag, logout and look at the console logs.

@boutell
Copy link
Member

boutell commented Jan 27, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants