question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React native not sending real file data to server (Meteor + Apollo).

See original GitHub issue

the client side mutation

const UPLOAD_IMAGE = gql`
  mutation uploadImage($file: Upload!) {
    uploadImage(file: $file)
  }
`;

const file = new ReactNativeFile({
  uri, // From camera roll
  name: 'testing',
  type: 'image/jpeg',
});

uploadAvatar({
  variables: {
    file,
  },
});

the client side setup

...
const httpLink = createUploadLink({ uri: api });
const link = split(
  // split based on operation type
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },
  wsLink,
  httpLink,
);

const client = new ApolloClient({
  link: ApolloLink.from([middleWareLink, errorLink, stateLink, authLink, link]),
  cache,
});

the server side setup (meteor)

import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas';

// Resolvers
import { accountTypeDefs, accountResolvers } from './account';
import { categoriesResolvers } from './categories';
...

// TypeDefs
import types from './schema.graphql';
// I have declared "scalar Upload" in schema.graphql already

const resolvers = mergeResolvers([
  ...accountResolvers,
  ...categoriesResolvers,
  ...
  {
    Upload: GraphQLUpload
  },
]);

const typeDefs = mergeTypes([...accountTypeDefs, types]);

const schema = makeExecutableSchema({ typeDefs, resolvers });

createApolloServer(
  {
    schema,
  },
  {
    graphiql: true,
    configServer: (expressServer) => {
      expressServer.use(bodyParser.json({ limit: '5mb' }));
      expressServer.use(graphqlUploadExpress());
    },
  },
);

The server receives an object instead of a Promise for further processing.

{
  uri, // From camera roll
  name: 'testing',
  type: 'image/jpeg',
}

I’ve read a lot of the related issues but not sure which parts are incorrect. thanks!!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
lauyilouiscommented, Nov 22, 2018

Hi @mike-marcacci @jaydenseric, you are right. It was the client side problem. There was a middleware link parsed the ReactNativeFile type to String. It was resolved after removing that link. Thank you very much!

1reaction
lauyilouiscommented, Aug 26, 2019

Hi @mike-marcacci @jaydenseric, you are right. It was the client side problem. There was a middleware link parsed the ReactNativeFile type to String. It was resolved after removing that link. Thank you very much!

Hi i am facing the same issue. I wonder which link that causes this problem .

Thanks xx

There was an Apollo link at Apollo Client acted as a middleware to ignore the typename for any mutation. It prevent the __typename is injected in the variable of any mutation but also stringify the of ReactNativeFile type so I removed it.

const middleWareLink = new ApolloLink((operation, forward) => {
  console.log('before', operation);
  if (operation.variables) {
    const omitTypename = (key, value) => (key === '__typename' ? undefined : value);
    // eslint-disable-next-line no-param-reassign
    operation.variables = JSON.parse(JSON.stringify(operation.variables), omitTypename);
  }
  console.log('after', operation);
  return forward(operation);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating with Meteor - Apollo GraphQL Docs
Connect your express server to Meteor's existing server with WebApp.connectHandlers.use; Do not end the connection with res.send() and res.end() use req.
Read more >
Upload image from React Native to Apollo Server not ...
I have created my backend with Nodejs and Apollo Server . I am trying to upload an image from my React Native client....
Read more >
1: GraphQL Set up
This package uses Meteor DDP as data layer and Apollo as GraphQL implementation. 1.2 Set up server. Create a new file called graphql.js...
Read more >
Building Chatty — Part 4: GraphQL Mutations
A WhatsApp clone with React Native and Apollo ... While GraphQL Queries let us fetch data from our server, GraphQL Mutations allow us...
Read more >
Meteor and React Native - Create a native mobile app
Meteor and React Native are not integrated with each other by default However, there are great packages out there, that help us to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found