question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQl: cant disable operations with yaml

See original GitHub issue

Hi iam using api/platform 3.0.7 and i want to modify graphql operations with yaml.

My yaml looks like this:

REST: i want only GET method GRAPHQL: i want enable only Query and Create mutation

Namespace\To\Entity:
    operations:
        ApiPlatform\Metadata\GetCollection: ~
        ApiPlatform\Metadata\Get: ~
    graphQlOperations:
        ApiPlatform\Metadata\GraphQl\Query: ~
        ApiPlatform\Metadata\GraphQl\Mutation:
            name: create

with REST (“operation” namespace) it works fine and i can see only GET methods. But with graphql i still can do collenctionQuery and all other mutations.

What am i doing wrong?

Thx for answer

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
durimjusajcommented, Dec 14, 2022

I have the same problem, after some research and debugging, I could find two issue related to this. ApiPlatform\Metadata\Extractor\YamlResourceExtractor => buildGraphQlOperations If collection is the first query in queries array, it will override all other queries as collection. I can see loop value overwritten in line 310 and 315 which are causing this problem.

ApiPlatform\Metadata\Resource\Factory\ExtractorResourceMetadataCollectionFactory => addGraphQlOperations attribute class is not filled, function addOperations has this getOperationWithDefaults which fixes name and other attributes, but is missing for graphql, this is why you have to specify class attribute in yaml directly.

my working yaml:

Namespace\To\Entity:
  operations: [ ]
  graphQlOperations:
    queries:
      ApiPlatform\Metadata\GraphQl\Query:
        class: Namespace\To\Entity
      ApiPlatform\Metadata\GraphQl\QueryCollection:
        collection: true
        class: Namespace\To\Entity

Also you can just send only array without operation class

Namespace\To\Entity:
  operations: [ ]
  graphQlOperations:
    queries:
      - class: Namespace\To\Entity
      - class: Namespace\To\Entity
        collection: true
0reactions
OndrosIcommented, Dec 16, 2022

@durimjusaj

Thank you, this works fine.

It would be nice to update documentation in next hotfix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Should Disable GraphQL Introspection In Production
In this post, we'll discuss why we believe you should disable GraphQL introspection in production, how to do it, and present a way...
Read more >
GraphQL Best Practices
While there's nothing that prevents a GraphQL service from being versioned just like any other REST API, GraphQL takes a strong opinion on...
Read more >
ESLint parser, plugin and set rules for GraphQL (for schema ...
ESLint parser, plugin and set rules for GraphQL (for schema and operations). Easily customizable with custom rules. Integrates with IDEs and modern GraphQL...
Read more >
API (GraphQL) - Client code generation - AWS Amplify Docs
yml file in the root folder of your project. When generating types, codegen uses GraphQL statements as input. It will generate only the...
Read more >
GraphQL Content API - Contentful
To prevent this error, make sure the field IDs you're using on each content type cannot result in the same GraphQL field name....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found