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

enhancement: support introspection #798

Closed
wants to merge 17 commits into from
Closed

Conversation

0xmovses
Copy link
Contributor

@0xmovses 0xmovses commented Apr 24, 2023

Closes #790

See the issue for full context, it's all there πŸ‘Œ

Changelog

β€’ Add introspect method on Schema struct.
β€’ Updates query_graph handler function to check for introspection and return that if requested.
β€’ Updates documentation.

Testing

  1. cargo run --bin fuel-indexer -- run --manifest packages/fuel-indexer-tests/components/indices/fuel-indexer-test/fuel_indexer_test.yaml
  2. In your browser, go to http://localhost:29987/api/playground/fuel_indexer_test/index1
  3. Send the query below
    (For extra testing you can test normal queries and other indexers, I did this, but if you're in a QA type of mood... )
query IntrospectionQuery {
  __schema {
    types {
      name
      fields {
        name
        type {
          name
          kind
        }
      }
    }
  }
}

You should get the response

{
  "data": {
    "__schema": {
      "mutationType": null,
      "queryType": {
        "name": "Query"
      },
      "subscriptionType": null,
      "types": [
        {
          "fields": [
            {
              "name": "QueryRoot",
              "type": {
                "kind": "NON_NULL",
                "ofType": {
                  "kind": "OBJECT",
                  "name": "QueryRoot"
                }
              }
            }
          ],
          "kind": "OBJECT",
          "name": "Query"
        },
        {
          "fields": [
            {
              "name": "gas_used",
              "type": {
                "kind": "NON_NULL",
                "ofType": {
                  "kind": "SCALAR",
                  "name": "UInt8!"
                }
              }
            },
            {
              "name": "id",
              "type": {
                "kind": "NON_NULL",
                "ofType": {
                  "kind": "SCALAR",
                  "name": "ID!"
                }
              }
            },
            {
              "name": "blob",
              "type": {
                "kind": "NON_NULL",
                "ofType": {
                  "kind": "SCALAR",
                  "name": "Blob!"
                }
              }
            },
            {
              "name": "result",
              "type": {
                "kind": "NON_NULL",
                "ofType": {
                  "kind": "SCALAR",
                  "name": "UInt8!"
                }
              }
            }
              ...

Note

mutationType and subscriptionType fields have been set to null.

deekerno and others added 10 commits April 21, 2023 15:47
Add filtering functionality to GraphQL API; add E2E tests
…ueries (#755)

* Add comments; rename to clearer variables

* Add sorting and offset-based pagination
* Add PageInfo object to queries with a limit

* Adjust tests

* Change API response to snake_case
* Add docs for GraphQL filtering and pagination

* Move QueryResponse to models module

* Address rvmelkonian feedback

* Address ra0x3 feedback
Copy link
Member

@luizstacio luizstacio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the PR locally here, I see the error

{
  "error": "Introspection result missing interfaces: { fields: [[Object]], kind: \"OBJECT\", name: \"Query\" }."
}

@0xmovses
Copy link
Contributor Author

@luizstacio I forgot to mention in the PR description, that error shows on initial page load, but if you run the introspection query, it should work. Could you try that? Meanwhile I'll see if I can suppress that error on page load.

@ra0x3
Copy link
Contributor

ra0x3 commented Apr 25, 2023

@rvmelkonian

  • Just an FYI doesn't seem to work for me either.
  • When I open the playground I do see the error @luizstacio mentions
  • When I click the "Schema" and the "Docs" tabs, I don't see anything -- I just see the loading spinner which never resolves

@0xmovses
Copy link
Contributor Author

@ra0x3 I had a sync with @luizstacio late last night. The scope of this PR was just to do the introspection query and get the response back with the schema data (this is used for TS code gen). To get the schema and docs stuff to work in the playground, I would consider a separate PR as that involves editing JS and html from async-graphql crate.

Did you try out the query in the description and get back a successful response?

@ra0x3
Copy link
Contributor

ra0x3 commented Apr 25, 2023

@rvmelkonian Sounds good. I'll defer to @luizstacio for approval in terms of functionality working properly

@luizstacio
Copy link
Member

luizstacio commented Apr 26, 2023

@rvmelkonian Sounds good. I'll defer to @luizstacio for approval in terms of functionality working properly

Docs and Schema tabs are loaded using the return of the introspect query, to be a valid return it should be loading this tabs also, this would give you the certainty that is working.

I was talk with @deekerno yesterday about investigate the possibility to use async-graphql dynamic schemas. In order to replace the current GraphQL Parser. This should enable this features without the need to custom implementations, and also make sure that the response of GraphQL returns comply with GraphQL standard.

I'm mentioning this here, because if @deekerno is looking into it, this work may not be needed?

@ra0x3
Copy link
Contributor

ra0x3 commented Apr 26, 2023

@deekerno Will defer to you with regard to @luizstacio 's comment here.

@0xmovses
Copy link
Contributor Author

@ra0x3 @deekerno In that case I'll put this PR on hold then #800 as I'm making heavy use of our current graphql parser. I'm all up for shifting to async-graphql, if we can get a compliant graphql endpoint out of the box that can support our needs, but I think this may require some rewrites elsewhere.

@deekerno
Copy link
Contributor

It will definitely require some rewrites; I think it's just a question of how many and how much effort we're willing to put into it. It seems like it may be a net positive as far as type safety, but I'm still investigating prior art to see if we would lose any speed or start running into any sort of "N+1 problem" when it comes to queries. I'll update you all on Slack.

@0xmovses
Copy link
Contributor Author

@luizstacio the logic for fetching the schema and docs is tucked away inside async-graphql crate. I'm only using that crate here to render out the playground, but everywhere else we are using our own fuel-indexer-graphql-parser package. This is why schema and docs do not load. But when you run the introspection query you should get all the data you need to be able to do TS gen. Let me know if this gives you what you need. πŸ‘Œ

Base automatically changed from feature/the-graphql-update to master April 26, 2023 19:43
@0xmovses 0xmovses mentioned this pull request Apr 27, 2023
@0xmovses
Copy link
Contributor Author

Closing this as async-graphql provides the functionality and we will be switching to this shortly.

@0xmovses 0xmovses closed this Apr 28, 2023
@ra0x3 ra0x3 deleted the rich/790-introspect-query branch June 29, 2023 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support introspection queries on GraphQL endpoint
4 participants