GithubHelp home page GithubHelp logo

learning-graphql's People

Contributors

brysgo avatar chentsulin avatar dabanlee avatar hamchapman avatar iamjoetaylor avatar kyleamathews avatar mugli avatar nikolasburk avatar rhberro avatar samerbuna avatar timmikeladze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learning-graphql's Issues

Amazing.

This is singularly the best GraphQL resource I know of. I've been recommending it to everyone!

Thanks for putting this together, it's been huge :)

Question about GraphQLInterfaceType

A little confused about the GraphQLInterfaceType documentation.

var NamedType = new GraphQLInterfaceType({
  name: 'Named',
  fields: {
    name: { type: GraphQLString }
  }
});

var DogType = new GraphQLObjectType({
  name: 'Dog',
  interfaces: [ NamedType ],
  fields: {
    name: { type: GraphQLString },
    barks: { type: GraphQLBoolean }
  },
  isTypeOf: (value) => value instanceof Dog
});

var CatType = new GraphQLObjectType({
  name: 'Cat',
  interfaces: [ NamedType ],
  fields: {
    name: { type: GraphQLString },
    meows: { type: GraphQLBoolean }
  },
  isTypeOf: (value) => value instanceof Cat
});

I don't understand why both the CatType and DogType have name as well as have the interfaces: [ NamedType ]. This seems redundant. What is the purpose of GraphQLInterfaceType?

https://github.com/mugli/learning-graphql/blame/master/7.%20Deep%20Dive%20into%20GraphQL%20Type%20System.md#L65-L90

Add More info on scalar types?

In your tutorial 7 you can add some more info on creating custom scalar types to do validation like this one,

var ValidateStringType = (params) => {
  return new GraphQLScalarType({
    name: params.name,
    serialize: value => {
      return value
    },
    parseValue: value => {
      return value
    },
    parseLiteral: ast => {
      if (ast.kind !== Kind.STRING) {
        throw new GraphQLError("Query error: Can only parse strings got a: " + ast.kind, [ast])
      }
      if (ast.value.length < params.min) {
        throw new GraphQLError(`Query error: minimum length of ${params.min} required: `, [ast])
      }
      if (ast.value.length > params.max){
        throw new GraphQLError(`Query error: maximum length is ${params.max}: `, [ast])
      }
      if(params.regex !== null) {
        if(params.regex.test(ast.value)) {
          throw new GraphQLError(`Query error: Not a valid ${params.name}: `, [ast])
        }
      }
      return ast.value
    }
  })
}

Mutations for nested resources

Hey. When I write my code I'm designing it not coding thus I have lots of questions :). Btw, I like your code style. How would you handle nested resources like /projects/:project_id/products/:id. All tutorials (not just yours) have mutations defined on the root mutation (no nesting). As I described here graphql/graphql-js#221 we could have nested resources the same way as we would do it in REST (nested query). I wonder if that logic is acceptable in graphql. I would like to see how others handle this case.

Example:

// PUT /projects/:project_id/products/:id
mutation {

  // example 1
  findProject(id: 1) { // make sure that the project exists and we can access it before mutating data
    updateProduct(id: 1, name: "Foo") { // the resolve function receives a valid `project` as the first arg
      id
    }
  } 

  // example 2
  updateProjectProduct(projectId: 10, name: "Product 1") {id}

  // example 3
  updateProjectProduct(projectId: 10, product: { name: "Product 1"}) {id}

}

Also, should the update or delete mutation return an object or null or {status: 'ok'} or else?

Thank you!

ValidateStringType error

Hi there,

This is more of a question than an issue but I thought you might have encounter the same problem at some point.

I took the code of the ValidateStringType to create a custom scalar type. Well, I tried just for having an id of 24 characters. And as soon as I use it in a query as an input, I get this:

[TypeError: Cannot read property 'test' of undefined]

I didn't manage to test anything but printing the IdType object. After that, it seems like nothing is executed, neither the query resolve function neither any of the parseValue, parseLiteral, serialize functions.

Any idea of what it could be ?

repository abandoned?

I don't think that after 3 years this will be continued, or am i wrong?
Since this is 3 years old already and gets older every day, the information given can already be deprecated but definitely will be at some point.
If you won't continue this work (which i appreciate, really) you should maybe put a big "possible deprecation"-warning topmost and link to the actual GraphQL-documentation :)

Validation for query variables

First of all, thanks a ton for this, it really helped me learn GraphQL. I wanted to suggest an addition in part 7 when you talk about creating custom scalar types for fine-grained validation. What you have there doesn't work at all if a query is using variables instead of arguments. That requires the validation to occur in parseValue instead of parseLiteral.

For example, if I have a custom scalar type defined using the docs you have currently (with only parseLiteral, this will be validated:

mutation {
  createUser (email: "invalidemail") { ... }
}

but this will not:

mutation signup ($email: Email!) {
  createUser (email: $email) { ... }
}

I'll submit a PR for this, hopefully it will clear things up for anyone using validation on queries with variables.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.