angel-dart / angel

[ARCHIVED] A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://angel-dart.dev/
MIT License
1.06k stars 67 forks source link

Running server with sdl schema #203

Closed thosakwe closed 3 years ago

thosakwe commented 4 years ago

This issue was originally created by @venkatd here, before being automatically moved: https://github.com/angel-dart-archive/graphql/issues/30


One of the Apollo server examples works something like this:

const { ApolloServer, gql } = require('apollo-server');

const books = [
  {
    title: 'Harry Potter and the Chamber of Secrets',
    author: 'J.K. Rowling',
  },
  {
    title: 'Jurassic Park',
    author: 'Michael Crichton',
  },
];

const typeDefs = gql`
  type Book {
    title: String
    author: String
  }
  type Query {
    books: [Book]
  }
`;

// Resolvers define the technique for fetching the types in the
// schema.  We'll retrieve books from the "books" array above.
const resolvers = {
  Query: {
    books: () => books,
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});

Is it possible to do something similar with angel-dart and graphql?

thosakwe commented 4 years ago

@thosakwe commented:

The parser doesn't parse the SDL just yet, but if you watch this PR, you'll know when the next version comes out (this is an intended feature): https://github.com/angel-dart/graphql/pull/27

It won't look exactly the same, but you'll be able to use graphql_parser to parse type definitions from text. One key difference here, though, is that in angel_graphql, the resolvers are coupled with the schema, instead of separating them (turns out to be less error-prone).

thosakwe commented 4 years ago

@venkatd commented:

@thosakwe could you explain what you mean by "the resolvers are coupled with the schema, instead of separating them"?

We are interested in moving to a single SDL schema shared by all of our codebases. Our Elixir backend will make use of this SDL schema in addition to some mobile clients. Some of our flutter clients will resolve some queries from a local cache while sending others directly to our backend. We will also make use of some code-generation tools off this SDL schema.