Skip to content

Prototype #1

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

Merged
merged 52 commits into from
Mar 23, 2020
Merged

Prototype #1

merged 52 commits into from
Mar 23, 2020

Conversation

mpenick
Copy link
Contributor

@mpenick mpenick commented Mar 5, 2020

Exploring GraphQL schema generation using C*/DSE schema metadata.

Extended it to support POST using `httprouter`.
@mpenick mpenick added the wip label Mar 5, 2020
@mpenick
Copy link
Contributor Author

mpenick commented Mar 5, 2020

My next step is to pull the DAL from https://github.com/riptano/cloud-ondemand/tree/master/data-endpoint/pkg/db and start to generate GraphQL schema from the schema metadata.

@mpenick
Copy link
Contributor Author

mpenick commented Mar 5, 2020

@jorgebay Feel free to modify this however, and push right to it.

@jorgebay
Copy link
Contributor

jorgebay commented Mar 5, 2020

Great way to kickstart the project 👍

@mpenick
Copy link
Contributor Author

mpenick commented Mar 6, 2020

Pushed basic read and schema generation functionality. Also integrated with your DB class and pushed a test schema with it: https://github.com/riptano/data-endpoints/blob/prototype/store.cql

Currently, the resolver for the select is in a big-ish closure which is not ideal (just getting stuff working/started). That needs to be extracted out and generalized so that we can easily add revolvers for create, update, and delete.

@jorgebay
Copy link
Contributor

jorgebay commented Mar 6, 2020

Nice!

I've added insert mutation and I'll push delete soon.

@jorgebay
Copy link
Contributor

jorgebay commented Mar 9, 2020

Here's the graphql query to create a table:

mutation TableMutation
{
  createTable(name:"sample", partitionKeys: [
    { name: "id1", type: { basic: INT } },
    { name: "id2", type: { basic: TEXT } }
  ], clusteringKeys: [
    { name: "ck1", type: { basic: INT } },
  ], values: [
    { name: "col2", type: { basic: TEXT } },
  ])
}

@mpenick
Copy link
Contributor Author

mpenick commented Mar 9, 2020

Table schema query:

query {
  table(name: "BooksByAuthor") {
    name
    columns {
      name
      kind
      type {
        basic
        subTypes {
          basic
        }
      }
    }
  }
  tables {
    name
    columns {
      kind
      type {
        basic
      }
    }
  }
}

@jorgebay
Copy link
Contributor

I've pushed a change to support graphql scalars for uuid and timestamp cql types:

Screen Shot 2020-03-10 at 13 10 32

We can later define per each scalar which are the acceptable format (ie: uuid values are still passed as strings).

@mpenick
Copy link
Contributor Author

mpenick commented Mar 17, 2020

Abstracted away the database and using routes as the boundary layer between our API and the Astra/Community server.

Names are placeholders. Feel free to change anything.

// Create configuration object
cfg := datastax.NewEndpointConfig("127.0.0.1")

// Configure here

// Create the endpoint
endpoint, err := cfg.NewEndpoint()
if err != nil {
	log.Fatalf("unable create new endpoint: %s", err)
}

// Generate routes and add them to router
routes, err := endpoint.RoutesGql("/graphql")
if err != nil {
	log.Fatalf("unable to generate graphql routes: %s", err)
}

router := httprouter.New()
for  _, route := range routes {
	router.HandlerFunc(route.Method, route.Pattern, route.HandlerFunc)
}

@mpenick
Copy link
Contributor Author

mpenick commented Mar 17, 2020

Put up a PR for "executeAs": #3

@jorgebay
Copy link
Contributor

API for plugin into an existing http server looks great.

@jorgebay
Copy link
Contributor

I've added support for <tableName}Filter() queries:

query {
  booksByAuthorFilter(filter: { firstname: { eq: "Isaac"}, lastname: { eq: "Asimov"}, title: { gte: "A" }}) {
    values { title, authorId }
  }
}

@mpenick
Copy link
Contributor Author

mpenick commented Mar 19, 2020

Merged in proxy execute. Removed redundant execute methods from the db package. Bind() from Query doesn't prepared statements, it's just a way to late bind or rebind parameters. It looks like queries are automatically prepared:

Query is automatically prepared if it has not previously been executed.

Working on fixing/abstracting naming conventions.

@mpenick
Copy link
Contributor Author

mpenick commented Mar 20, 2020

I used your idea and moved the naming conventions to a central interface and the default implementation is stateless (following the existing rules). I started with a PR (#5), but I don't want to block your work tomorrow and/or end up with a bunch of conflicts so I pulled it in. Seriously, feel free to change anything you don't like or disagree with.

I also moved the GraphQL routes and schema methods into structs. This is because the number of parameters that needed to be passed around was getting out of control.

@jorgebay
Copy link
Contributor

Naming convention interface is looking great, the different methods give us the flexibility to handle different use cases.

I also moved the GraphQL routes and schema methods into structs

Good idea

@jorgebay
Copy link
Contributor

hm... it seems that graphql-go doesn't correctly handle null arguments, even though it's part of the spec: graphql/graphql-spec@3ce8b79 (more background: graphql/graphql-js#133)

@mpenick
Copy link
Contributor Author

mpenick commented Mar 20, 2020

Using that RFC and the existing PR I've created a fork with a mostly working patch: mpenick/graphql@3a00f1f

@jorgebay
Copy link
Contributor

Nice! let's see if we can merge it in the graphql-go project.
Otherwise, we could maintain the fork for the first phases of this project.

@mpenick mpenick merged commit 285d251 into master Mar 23, 2020
@mpenick mpenick deleted the prototype branch April 24, 2020 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants