Skip to content

Add records to dns zone in graphql #470

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

Closed
kuon opened this issue Nov 10, 2024 · 7 comments · Fixed by #471
Closed

Add records to dns zone in graphql #470

kuon opened this issue Nov 10, 2024 · 7 comments · Fixed by #471
Assignees
Labels
enhancement New feature or request

Comments

@kuon
Copy link

kuon commented Nov 10, 2024

I am using graphql to grab DNS data from netbox DNS, and at present I have to do N queries for zones.

    {
      netbox_dns_zone_list {
        id
        name
        custom_fields
        default_ttl

        nameservers {
          name
        }
      }
    }

Then for each zone:

    {
      netbox_dns_record_list(filters:{zone_id: ID_FROM_PREVIOUS_QUERY}) {
        name
        custom_fields
        type
        value
        ttl
      }
    }

Being able to do this:

    {
      netbox_dns_zone_list {
        id
        name
        custom_fields
        default_ttl

        nameservers {
          name
        }
       records {
        name
        custom_fields
        type
        value
        ttl
      }
      }
    }

Would greatly increase performances.

@peteeckel
Copy link
Owner

Hi @kuon, this is a duplicate of #450.

The relation is from record to zone, and the current implementation of Strawerry with NetBox unfortunately does not create the reverse relation. See also this NetBox issue.

@peteeckel peteeckel added duplicate This issue or pull request already exists enhancement New feature or request labels Nov 10, 2024
@kuon
Copy link
Author

kuon commented Nov 10, 2024

I saw #450 but I didn't realize it was the same issue as I thought the relation was zone->records. But it makes sense. Sorry for the duplicate. Thanks.

@peteeckel
Copy link
Owner

peteeckel commented Nov 10, 2024

No problem.

I'll have a look at it later this week, maybe it will be possible to provide a workaround until netbox-community/netbox#17242 is resolved. At least for this issue, because we control both ends of the relation. #450 is different in that we don't have a chance there because one end is a core model.

@peteeckel peteeckel reopened this Nov 10, 2024
@peteeckel
Copy link
Owner

I just tried it, and it is possible to use the standard Django reverse relations and rename them so they make sense in GraphQL.

Might take a couple of days because I'm quite busy atm, but it doesn't seem to be a big deal right now.

@kuon
Copy link
Author

kuon commented Nov 10, 2024

There is no emergency, it is only performance optimization. Thank you a lot for your work.

@peteeckel
Copy link
Owner

query MyQuery {
  netbox_dns_zone_list {
    name,
    view {name},
    records {
      name,
      type,
      value
    }
  }
}
{
  "data": {
    "netbox_dns_zone_list": [
      {
        "name": "0.0.10.in-addr.arpa",
        "view": {
          "name": "_default_"
        },
        "records": [
          {
            "name": "@",
            "type": "NS",
            "value": "ns1.example.com."
          },
          {
            "name": "@",
            "type": "NS",
            "value": "ns2.example.com."
          },
          {
            "name": "@",
            "type": "SOA",
            "value": "ns1.example.com. hostmaster.example.com. 1722355158 172800 7200 2592000 3600"
          },
...

@peteeckel
Copy link
Owner

I'll work trough all the relations where this makes sense, and I still need to check how it affects automatic testing.

@peteeckel peteeckel removed the duplicate This issue or pull request already exists label Nov 11, 2024
@peteeckel peteeckel self-assigned this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants