https://www.prisma.io/ logo
Join Slack
Powered by
# prisma-whats-new
  • g

    gajus

    08/21/2016, 9:19 PM
    and I would enjoy those sweet re-tweets ๐Ÿ™‚
  • g

    gajus

    08/22/2016, 10:32 AM
    I am probably missing something
  • g

    gajus

    08/22/2016, 10:32 AM
    I cannot find how to parse GraphQL schema definition
  • g

    gajus

    08/22/2016, 10:32 AM
    Suppose I have this
  • g

    gajus

    08/22/2016, 10:32 AM
    Copy code
    schema {
      query: Query
      mutation: Mutation
    }
    type Blog {
      id: ID!
      eventName: String
      eventUrl: String
      eventStartAt: String
      eventEndAt: String
      posts: [Post]
    }
    input CreateBlogInput {
      eventName: String
      eventUrl: String
      eventStartAt: String
      eventEndAt: String
    }
    input CreatePostInput {
      blogId: ID!
      name: String!
      body: String!
      imageUrl: String
    }
    input DeletePostInput {
      id: ID!
    }
    type Mutation {
      createBlog(blog: CreateBlogInput): Blog
      createPost(post: CreatePostInput): Post
      deleteBlog(id: ID!): Blog
      deletePost(post: DeletePostInput): Post
      updateBlog(blog: UpdateBlogInput): Blog
      updatePost(post: UpdatePostInput): Post
    }
    type Post {
      id: ID!
      name: String!
      body: String!
      blog: Blog
    }
    type Query {
      user(id: ID!): User
      blog(id: ID!): Blog
    }
    input UpdateBlogInput {
      eventName: String
      eventUrl: String
      eventStartAt: String
      eventEndAt: String
    }
    input UpdatePostInput {
      id: ID!
      name: String
      body: String
      imageUrl: String
    }
    type User {
      id: ID!
      firstName: String!
      lastName: String!
    }
  • g

    gajus

    08/22/2016, 10:32 AM
    How to I convert that to JavaScript object?
  • s

    sorenbs

    08/22/2016, 10:35 AM
    Hey @gajus - what's the context? Are you doing a query using Lokka/relay/apollo?
  • g

    gajus

    08/22/2016, 10:36 AM
    Not using any client. Writing an API server. I want to define my schema as a string. Parse it into an object. Then for each type that requires it โ€“ย define resolvers.
  • g

    gajus

    08/22/2016, 10:40 AM
    https://medium.com/apollo-stack/graphql-js-the-hidden-features-effaca7a81b3#7182
  • g

    gajus

    08/22/2016, 10:40 AM
    Found my answer here
  • g

    gajus

    08/22/2016, 10:40 AM
    albeit it requires using a third-party tool
  • s

    sorenbs

    08/22/2016, 10:42 AM
    I see. Glad you found a solution ๐Ÿ™‚ We are doing something similar but wrote our own parser
  • g

    gajus

    08/22/2016, 10:42 AM
    Whats the reason for needing to write your own parser?
  • g

    gajus

    08/22/2016, 10:43 AM
    and when you say "we", who are you referring to? Interested to subscribe to what other people/ companies do with GraphQL.
  • s

    sorenbs

    08/22/2016, 10:45 AM
    By we I mean graph.cool ๐Ÿ™‚
  • g

    gajus

    08/22/2016, 10:46 AM
    Ah, so you are one of the developers of graph.cool. Thats cool. Already following you. : )
  • s

    schickling

    08/22/2016, 12:41 PM
    Hey @gajus! Have you already checked out this package? https://github.com/matthewmueller/graph.ql
  • g

    gajus

    08/22/2016, 12:59 PM
    @schickling I have seen it. One of the things I dislike about it is that it requires to declare the entire schema and all loaders in one-go (as far as I can tell).
  • g

    gajus

    08/22/2016, 12:59 PM
    However, what I am doing at the moment is primarily for learning purposes.
  • s

    schickling

    08/22/2016, 12:59 PM
    @gajus yeah I see ๐Ÿ™‚
  • g

    gajus

    08/22/2016, 1:40 PM
    @schickling Whats the reason for implementing your own parser?
  • g

    gajus

    08/22/2016, 1:40 PM
    Unless I am missing something, graph.ql can be implemented in couple of lines of code
  • g

    gajus

    08/22/2016, 1:41 PM
    Copy code
    const getSchemaTypeField = (schema, typeName, fieldName) => {
      const type = schema.getType(typeName);
    
      if (type === undefined) {
        throw new Error('"' + typeName + '" type does not exist in the schema.');
      }
    
      const fields = type.getFields();
    
      const field = fields[fieldName];
    
      if (field === undefined) {
        throw new Error('"' + typeName + '" type does not have "' + fieldName + '" field.');
      }
    
      return field;
    };
    
    const addResolveToSchemaMethod = (schema, typeName, fieldName, resolveFunction) => {
      const field = getSchemaTypeField(schema, typeName, fieldName);
    
      field.resolve = resolveFunction;
    };
    
    addResolveToSchemaMethod(schema, 'Query', 'user', () => {
      return {
        id: '2'
      }
    });
    
    addResolveToSchemaMethod(schema, 'User', 'id', () => {
      return '3';
    });
  • g

    gajus

    08/22/2016, 1:41 PM
    as an example
  • s

    schickling

    08/22/2016, 2:05 PM
    It's less about the parsing part but more about the wiring behind the scenes to connect it to a database etc ๐Ÿ™‚
  • o

    olivierandriessen

    08/22/2016, 4:13 PM
    Hi ๐Ÿ‘‹
    ๐Ÿ™Œ 2
  • n

    nilan

    08/22/2016, 4:14 PM
    hi @olivierandriessen โœ‹
  • r

    rene

    08/22/2016, 4:14 PM
    welcome @olivierandriessen
  • g

    gerardsans

    08/24/2016, 12:19 PM
    Join the other 200 RSVPs! Just few more hours before the LIVE streaming Today! Don't miss out this chance to catch up on the amazing Angular CLI w Mike Brocchi covering: webpack, 3rd party imports, lazy loading and more! http://www.meetup.com/AngularZone/events/233062462
  • p

    praneybehl

    08/25/2016, 9:15 AM
    Hi guys, just wondering whatโ€™s the go with on-boarding new users. How long is it currently taking?
    ๐Ÿ‘ 1
1...111213...637Latest