-
I'm currently in the process of porting NetBox DNS to NetBox 4. Currently I'm working on the GraphQL migration to strawberry. Generally the migration is working fine, however I have some issues with generating filters using the Problem with filtering on annotations for a modelThe
Definition of the annotation:
Definition in the filterset:
When I disable the definition in the filter, the error does not occur. It would help to be able to define that GraphQL filter manually and have it be ignored by Problem with custom fieldsFor the
I assume something similar has to be done for strawberry, but couldn't find out how to do it yet. I could also live with having the fields excluded from filtering in GraphQL, as they are not really providing end user functionality.
First call to the GraphQL API is extremely slowAfter a NetBox restart, the first call (per worker) to the GraphQL API is very slow, all subsequent calls are almost instantaneous:
Is this expected, or is there anything wrong? The GUI and the REST API do not show this behaviour. Maybe @arthanson can shed some light on this? I'll investigate further and see what I can figure out as well. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 3 replies
-
@peteeckel I'll try and take a look later today |
Beta Was this translation helpful? Give feedback.
-
I found one workaround (albeit an ugly one) for the first two issues:
That way, at least the other fields can be used for filtering. |
Beta Was this translation helpful? Give feedback.
-
I must correct myself - at least the GUI shows the same behaviour. |
Beta Was this translation helpful? Give feedback.
-
Update: I can query the annotated field
So it's very likely not a strawberry issue but one with |
Beta Was this translation helpful? Give feedback.
-
@peteeckel Answers to some of your issues / questions:
|
Beta Was this translation helpful? Give feedback.
-
Hi @arthanson, thanks for the detailed response!
When the long response time issue occurs, the worker in question is at 100% CPU for a while, then goes back to normal. Thanks a lot, that really helped, apart from the
Apparently some conversion from JSON to a |
Beta Was this translation helpful? Give feedback.
-
OK, that was filter syntax. This one works differently wrong:
For some reason the PostgreSQL query generated for the GraphQL query contains illegal curly braces:
Fun fact: It works perfectly on model level:
And via the REST API:
|
Beta Was this translation helpful? Give feedback.
-
I could fix the problem with And the best thing: It works, out of the box - so item 1 is fixed as well. |
Beta Was this translation helpful? Give feedback.
-
What do you think the problem with the broken PostgreSQL query comes from:
ATM I'm a bit lost where to start searching ... |
Beta Was this translation helpful? Give feedback.
-
@peteeckel I've put in a PR to fix issue 1, it will skip fields not defined on the model so you will just need to explicitly define it on the GraphQL filter class. Should hopefully be merged in a day or so. For item 4, there is a delay in startup time as Strawberry processes all the typing - it seems very slow at it for some reason. It just effects startup, so it is a one-time hit, but we are looking into it. It currently looks like it is an issue with Strawberry, so I may have to open up an issue with them. |
Beta Was this translation helpful? Give feedback.
-
Update regarding the three functional issues: All of them have been fixed thanks to @arthanson's input. I implemented a hacked version of the GraphQL tests (necessary because I needed to modify the GraphQL Query class names and prefixes to avoid name clashes, which is to some extent my own fault) and all of them pass as well. The only thing that's really annoying is the long startup time. That doesn't only affect GraphQL API operations but everything, from NetBox worker startup time over |
Beta Was this translation helpful? Give feedback.
-
Unfortunately this has been un-fixed in one of the last commits ... not sure when it happened as it's difficult to bisect because of intervening migrations. March 25th:
April 2nd:
|
Beta Was this translation helpful? Give feedback.
@peteeckel Answers to some of your issues / questions:
I'll have to look into supporting this, will probably have to skip it in the autotype_decorator and have it defined explicitly in your GraphQL code.
If you have a custom type defined for them you can just add a @strawberry.type to it (see: https://github.com/netbox-community/netbox/blob/feature/netbox/ipam/graphql/mixins.py#L13) or in the typing you can just define the field return type (
prefix: str
)I think …