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

    danielvdm

    07/21/2017, 9:35 AM
    hey guys, what would be an appropriate place to map a graphql response into a js model object?
  • d

    danielvdm

    07/21/2017, 9:40 AM
    i'm trying to solve this problem of having a flow
    Type
    but also needing a model object
  • d

    danielvdm

    07/21/2017, 9:40 AM
    Copy code
    export type ListingType = {
      uuid: string,
      headline: string,
      slug: string,
      locationString: string,
      photos: [PhotoType],
    };
  • d

    danielvdm

    07/21/2017, 9:40 AM
    this represents the response from graphql
  • d

    danielvdm

    07/21/2017, 9:41 AM
    but now what if I want some helper functions on here for something like finding the primary photo?
  • d

    danielvdm

    07/21/2017, 9:41 AM
    Copy code
    get primaryPhoto(): ?PhotoType {
        const photo = this.photos.find(p => !!p.isPrimary);
        return photo;
      }
  • d

    danielvdm

    07/21/2017, 9:41 AM
    Copy code
    export class ListingModel {
      uuid: string;
      headline: string;
      slug: string;
      locationString: string;
      photos: [PhotoType];
    
      get primaryPhoto(): ?PhotoType {
        const photo = this.photos.find(p => !!p.isPrimary);
        return photo;
      }
    }
  • d

    danielvdm

    07/21/2017, 9:41 AM
    then I need something like this
  • d

    danielvdm

    07/21/2017, 9:42 AM
    but now I have these two types and it's kind of ugly to use them both in the same file
  • d

    danielvdm

    07/21/2017, 9:42 AM
    e.g. if the Props on my component are
    Copy code
    type Props = {
      data: {
        allListings: Array<ListingType>,
      },
    };
  • d

    danielvdm

    07/21/2017, 9:43 AM
    then I need something like
    Copy code
    get listings(): Array<ListingModel> {
      const { allListings } = this.props.data;
      return allListings.map(listing => new ListingModel(listing));
    }
  • d

    danielvdm

    07/21/2017, 9:43 AM
    ¯\_(ツ)_/¯
  • d

    danielvdm

    07/21/2017, 9:43 AM
    doesn't seem clean
  • d

    danielvdm

    07/21/2017, 9:48 AM
    maybe something like this
  • d

    danielvdm

    07/21/2017, 9:48 AM
    Copy code
    export default graphql(listingsQuery, {
      props: ({ data: { search } }) => ({
        listings: search.map(ListingModel),
      }),
    })(Home);
  • g

    giedriusr

    07/21/2017, 12:38 PM
    Unhandled GraphQL subscription error. The provided query doesn't include any known model name.
  • g

    giedriusr

    07/21/2017, 12:38 PM
    Where could an issue?
    n
    • 2
    • 36
  • f

    freddie-codogo

    07/21/2017, 2:09 PM
    Hi all, is there a recomened way for dealing with `Apollo`'s
    dataIdFromObject
    and
    customResolvers
    properties using a graph.cool simple API?
  • g

    giedriusr

    07/21/2017, 2:50 PM
    what could be wrong that I add new record via mutation, but the list is not being updated.. if I refresh the simulator I see updated list in the end
  • g

    giedriusr

    07/21/2017, 2:51 PM
    following this article: https://medium.com/react-native-training/full-stack-react-native-development-using-graphcool-and-apollo-subscriptions-react-navigation-cdb3e1374c05
  • g

    giedriusr

    07/21/2017, 2:51 PM
    and the example above works, but it wraps screens in tab navigator, but I do it with StackNavigator
  • g

    giedriusr

    07/21/2017, 2:51 PM
    could that be a problem?
  • j

    joshjoe

    07/21/2017, 4:08 PM
    How can an enum be used in a gql mutation call? Right now I’m passing the string reference from a form, but it isn’t excepting it since it expects an enum
    a
    n
    • 3
    • 23
  • f

    frankspin

    07/21/2017, 6:23 PM
    Trying to implement subscriptions in my nuxt.js project. Getting this response back: net::ERR_EMPTY_RESPONSE
    n
    • 2
    • 3
  • f

    frankspin

    07/21/2017, 7:38 PM
    What is the correct way to implement refetchQueries?
  • f

    frankspin

    07/21/2017, 7:38 PM
    Copy code
    export const actions = {
      getClients(context) {
        const getClientsQuery = apolloClient.query({
          query: gql `
    					{
    						allClients {
    							id
    							name
    						}
    					}
            `,
          refetchQueries: [getClientsQuery]
        }).then((result) => {
          context.commit('SET_CLIENTS', result.data.allClients);
        }).catch((error) => {
          console.log('error', error)
        })
      }
    }
  • f

    frankspin

    07/21/2017, 7:38 PM
    this isn't working
  • a

    auser

    07/21/2017, 9:20 PM
    is there a way to search by a string value?
  • a

    auser

    07/21/2017, 9:21 PM
    so instead of an
    ID!
    , can we search by a string value on a record
  • m

    mikael

    07/21/2017, 9:26 PM
    @auser example from the React+Apollo tutorial on howtographql
    Copy code
    query AllLinksSearchQuery($searchText: String!) {
        allLinks(filter: {
          OR: [{
            url_contains: $searchText
          }, {
            description_contains: $searchText
          }]
        }) {
          id
          url
          description
          createdAt
          postedBy {
            id
            name
          }
          votes {
            id
            user {
              id
            }
          }
        }
      }
1...280281282...637Latest